Following are the steps to reproduce the issue:

- Create user date field e.g. field_user_date and add some sample users
- Set the value of 'field_user_date' for some users
- Create a user view with 'field_user_date' filter as exposed filter and also expose it's operator
- visit the view page and directly select Is empty(null) and click Apply
- You will see that results are incorrect, it is showing the users for which 'field_user_date' is not NULL

Now use some other value of exposed operator e.g. "Is greater than" and apply 'Is empty(null)' again, the results will appear perfectly.

Any suggestions ?

CommentFileSizeAuthor
#12 1797630.patch1.37 KBdamiankloip
#11 Date_is_null.PNG20.28 KBwebby7097
#7 Capture.png56.95 KBwebby7097
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

qasimzee’s picture

ping

qasimzee’s picture

Added following lines in date/date_views/includes/date_views_filter_handler_simple.inc after line 102:

      if ($input[$this->options['expose']['operator_id']] == 'empty') {
        $input[$this->options['expose']['identifier']]['value'] = '1000-10-01'; 
      }

The diff looks something like:

function accept_exposed_input($input) {
     if (!empty($this->options['exposed'])) {
+      if ($input[$this->options['expose']['operator_id']] == 'empty') {
+        $input[$this->options['expose']['identifier']]['value'] = '1000-10-01';  //Fix for #1101
+      }
       $element_input = $input[$this->options['expose']['identifier']];
       $element_input['value'] = $this->get_filter_value('value', !empty($element_input['value']) ? $element_input['value'] : '');
       $element_input['min'] = $this->get_filter_value('min', !empty($element_input['min']) ? $element_input['min'] : '');

I am not sure if it is the correct approach or not. I was unable to create a patch by the way. Please suggest a better solution

jason.fisher’s picture

Issue summary: View changes

This issue is in the latest dev release.

I had to set the range values also for this 'fix' to work:

      if ($input[$this->options['expose']['operator_id']] == 'empty') {
        $input[$this->options['expose']['identifier']]['value'] = '2020-01-01';
        $input[$this->options['expose']['identifier']]['min'] = '2020-01-01';
        $input[$this->options['expose']['identifier']]['max'] = '2020-01-01';
      }

There must be a better place for this?

jason.fisher’s picture

Title: 'Is empty(null)' views filter is not working. » 'Is empty(null)' views filter is not working with exposed operators enabled when actual date values are left empty
Kiwa’s picture

I encountered the same bug today. Neither 'Is empty(null)' nor 'Is not empty (not null)' appear to work correctly for date fields.

Kiwa’s picture

Small update - tried the combined hack of #2 and #3 for a quick fix till a real fix is available, but it did not solve the problem for me.

webby7097’s picture

FileSize
56.95 KB

Having the same problem, though I don't have the filter exposed. I checked the database and the field I'm checking (field_alert_start_value2) is not null; I have a date field with a start and end, and when the end date is removed, the end date database field is updated to show the same date as the start date. So, despite the fact that when I edit the content it shows no end date, my database shows what's in the attached image.

webby7097’s picture

I've also tested creating a new node with no end date, and the same thing happens - the start date info is added to the end date field.

webby7097’s picture

One more piece of information - I apologize for the multiple posts, I'm checking these things as they occur to me - the server I have that is still running dates version 2.6 also shows dates in the database as outlined above. However - the view filter works - where an end date is not set in edit, the node is correctly included by the view with the IS NULL filter.

sonicthoughts’s picture

not sure if this is related but i do not even see the option for null or empty with the date field. are you referring to regex option?

webby7097’s picture

FileSize
20.28 KB

See the attached image - it shows the filter operator 'is Null'.

damiankloip’s picture

Status: Active » Needs review
FileSize
1.37 KB

I hit the same problem today. It's because the date_views_filter_handler does not override the empty op method like it does for others like between, simple, etc... So it tries to use its field name from views data where it's declared, which is 'date_filter', and not from the date_fields options.

Attached patch fixes this for me.

Fabianx’s picture

Status: Needs review » Reviewed & tested by the community

RTBC - looks great to me.

chris@frwonline.com’s picture

Tried the patches of #12 is not work for both empty / not empty operator, but #3 is work for me with including 'not empty'

      if ($input[$this->options['expose']['operator_id']] == 'empty' || $input[$this->options['expose']['operator_id']] == 'not empty') {
        $input[$this->options['expose']['identifier']]['value'] = '2020-01-01';
        $input[$this->options['expose']['identifier']]['min'] = '2020-01-01';
        $input[$this->options['expose']['identifier']]['max'] = '2020-01-01';
      }
podarok’s picture

Category: Bug report » Task
Priority: Normal » Critical
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

#12 merged.

  • podarok committed 2a62136 on 7.x-2.x authored by damiankloip
    Issue #1797630 by damiankloip, webby7097, Fabianx: 'Is empty(null)'...
vitalie’s picture

Patch #12 does not solve the issue. It looks like root cause of it is in Views. There are patches that solve it:

https://www.drupal.org/node/1776332
https://www.drupal.org/node/2445745

RoSk0’s picture

Status: Needs work » Fixed

Assuming fixed because included in 7.x-2.10 release.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.