I would like to group some issues around the exposed and grouped date field that are using the empty or not empty choice.
Here are the very easy steps to reproduce this bug:
1-create new content type with a date field (only Year, month and day) AND DO NOT SET A DEFAULT VALUE
2-create a view [based on this content type] with this date fields as exposed filter (grouped)
3-In the "grouped filters" UI, add 2 choices for the group "Is empty" and "is not empty"
4-Add some value and test the filter
=>See the attached screenshot to quickly understand this setup.

As you can see, in the screenshot, the filter is not working.

Why I would like to group some issues?

Because I found several patches that solve partially or not this simple issue; but none of them are fully working.
Here are the other issues/patches:
TITLE: views_handler_filter_date cannot filter for NULL
https://www.drupal.org/node/1776332#comment-10751604 [comment #5]

TITLE: Error when configuring exposed group filter: "The value is required if title for this item is defined."
https://www.drupal.org/node/1818176#comment-8807683 [comment #20]

TITLE: CCK field is empty/not empty filter doesn't work when exposed
https://www.drupal.org/node/477984#comment-8861095 [comment #80]

=>This issues is coming from the "date" module
TITLE: Exposed grouped filter for date not working
https://www.drupal.org/node/1876168#comment-10455497 [comment 71] =>comment 93 do not seems to work

I hope i have not made something wrong by trying to group those issues

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DuneBL created an issue. See original summary.

DuneBL’s picture

Sorry, but I think that

TITLE: Error when configuring exposed group filter: "The value is required if title for this item is defined."
https://www.drupal.org/node/1818176#comment-8807683 [comment #20]

is not linked to the exposed/grouped date field problem

mitsuroseba’s picture

After quick research found that the problem is in accept_exposed_input method at class views_handler_filter_date that doesn't allow operators with non values (like empty and not empty).

contrib/views/handlers/views_handler_filter_date.inc:144

    if ($operators[$operator]['values'] == 1) {
      if ($this->value['value'] == '') {
        return FALSE;
      }
    }
    else {
      if ($this->value['min'] == '' || $this->value['max'] == '') {
        return FALSE;
      }
    }
DuneBL’s picture

Thanks mitsuroseba for your input

Unfortunately, this is not solving the problem, and this is one of the issue/patch I am talking about in the first post:

TITLE: views_handler_filter_date cannot filter for NULL
https://www.drupal.org/node/1776332#comment-10751604 [comment #5]

But you are right, this patch is needed!

mitsuroseba’s picture

Oh, sorry for patch.

Which version of date and views do you use? Cause I can't reproduce your issue with my env.

My environment:
date 7.x-2.x
views 7.x-3.x
+patch https://www.drupal.org/node/1776332#comment-10751604 [comment #5]

My test case:
Exposed filter settings:
https://www.dropbox.com/s/6axch0jnfvr6w4c/%D0%A1%D0%BA%D1%80%D0%B8%D0%BD...
Results for empty in admin preview:
https://www.dropbox.com/s/3sjs52htdcyqv40/%D0%A1%D0%BA%D1%80%D0%B8%D0%BD...
Results for non empty in admin preview:
https://www.dropbox.com/s/8g93zz306wiljmt/%D0%A1%D0%BA%D1%80%D0%B8%D0%BD...
Results for non empty in test view page:
https://www.dropbox.com/s/aqx5kdjn8hn6cmk/%D0%A1%D0%BA%D1%80%D0%B8%D0%BD...

DuneBL’s picture

@mitsuroseba, looking at your dropbox images, your view setup looks like mine...
Here is my module's config:
date-7.x-2.9+6-dev (7.x-2.x-dev)
With one patch:
Exposed grouped filter for date not working
https: https://www.drupal.org/node/1876168#comment-10344663 [comment #71]

views-7.x-3.13+29-dev (7.x-3.x-dev)
With 3 patches:
TITLE: views_handler_filter_date cannot filter for NULL
https://www.drupal.org/node/1776332#comment-10751604 [7.x-3.x-devcomment #5]

TITLE: Error when configuring exposed group filter: "The value is required if title for this item is defined."
https://www.drupal.org/node/1818176#comment-8807683 [comment #20]

TITLE: CCK field is empty/not empty filter doesn't work when exposed
https://www.drupal.org/node/477984#comment-8861095 [comment #80]

And here is the query:

SELECT node.title AS node_title, node.nid AS nid, node.language AS node_language, node.created AS node_created, 'node' AS field_data_field_date1_node_entity_type
FROM 
{node} node
WHERE (( (node.status = '1') AND (node.type IN  ('test')) ))
ORDER BY node_created DESC
LIMIT 5 OFFSET 0

Note that the query doesn't change if I select "Is empty", "Is not empty" or "--any--" in the exposed filter for the date field... This is clearly the origin of the problem.
Just to make sure, there is no difference between us:
Use AJAX=yes
and, in the settings link near Content: date1 (Exposed Select Day) [below "Filter criteria"] =>see the screenshot
Date selection form element = select
Filter granularity = day
Starting year = -3 year from now
Ending year = +3 year from now

gravisrs’s picture

Status: Needs review » Reviewed & tested by the community

#3 works flawlessly

I've tested many scenarios with it and it should solve the case in all of them.

This patch should hit repo ASAP.

MustangGB’s picture

DamienMcKenna’s picture

Status: Reviewed & tested by the community » Closed (duplicate)
Parent issue: #2960871: Plan for Views 7.x-3.23 release »