I have an exposed "grouped" filter for a date field (field has start and end dates but I expose the start date).
I have 2 options:
- Any -
"Future Events", greater or equal to a relative date "now".

When I preview the view and test the filter, it works.
When I try it on the actual page, it's not working.

CommentFileSizeAuthor
#28 view-group-filter-prob.png203.5 KBsupradhan
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dagmar’s picture

Tagging

Jehu’s picture

subscribe.
Same problem here.

blackandcode’s picture

For me filters are compleatly broken. Select boxes don't work. This is very good option but It has A LOT OF BAGS.

dagmar’s picture

@blackandcode: Please help us to fix the issue, I personally worked a lot of days (I mean, almost 2 years) for free to provide this feature, your comment is not helping.

Please follow the the Views issue submission guidelines.

KuroNeko’s picture

subscribe

chartmann’s picture

subscribe

Dave Kopecek’s picture

First, this is a wicked-cool addition. Many thanks to all involved. I'm having issues with grouped date filters as well. I'm using Views 7.x-3.5 and Date Views 7.x-2.6. In this test case I'm trying to create an exposed grouped filter on a node->posted field. Here's what I've been able to determine.

There are a couple ways that a date filter can be created:

  1. By selecting the field from the "Content" dropdown in "Add filters" i.e "Content:Post date"
  2. By selecting "Date" from the dropdown in the "Add filters" section

Once the field has been selected, dates can be entered in a machine readable format "2012-01-01 00:00:00" or in offset format "-1 day".

  1. Using #1 above with a machine readable date works for me.
  2. Using #1 above with an offset date does not work, the "offset" radio button value does not save correctly and defaults back to the machine-readable option.
  3. Using #2 above does not work with either machine-readable or offset, the input box to for entering the date is missing from the widget.

My goal is to get the #1 "offset" method working. This opens up all kinds of reporting options. If anybody has any experience mucking around in the belly of the date widget and has any hints I'll follow up on them.

Dave Kopecek’s picture

Followup to #7. I created a view with 3 date filters in a group. Here's an export of the group section:

$handler->display->display_options['filters']['created']['group_info']['group_items'] = array(
  1 => array(
    'title' => 'TEST-SINGLE-VALUE',
    'operator' => '>=',
    'value' => array(
      'type' => 'date',
      'value' => '2012-01-01 00:00:00',
      'min' => '',
      'max' => '',
    ),
  ),
  2 => array(
    'title' => 'TEST-IS-BETWEEN',
    'operator' => 'between',
    'value' => array(
      'type' => 'date',
      'value' => '',
      'min' => '2012-02-01 00:00:00',
      'max' => '2012-03-01 00:00:00',
    ),
  ),
  3 => array(
    'title' => 'TEST-OFFSET',
    'operator' => '<=',
    'value' => array(
      'type' => 'offset',
      'value' => '-2 weeks',
      'min' => '',
      'max' => '',
    ),
  ),
);

All three date value types are correctly saved in the views definition, however when filter is recalled in the views UI "TEST-OFFSET" type->'offset' does not get recalled:

<div class="form-item form-type-radios form-item-options-group-info-group-items-3-value-type">
<!-- DIVs removed for space -->
<input id="edit-options-group-info-group-items-3-value-type-date" class="form-radio viewsImplicitFormSubmission-processed" type="radio" checked="checked" value="date" name="options[group_info][group_items][3][value][type]">
<label class="option" for="edit-options-group-info-group-items-3-value-type-date">A date in any machine readable format. CCYY-MM-DD HH:MM:SS is preferred. </label>
</div>
<div class="form-item form-type-radio form-item-options-group-info-group-items-3-value-type">
<input id="edit-options-group-info-group-items-3-value-type-offset" class="form-radio viewsImplicitFormSubmission-processed" type="radio" value="offset" name="options[group_info][group_items][3][value][type]">
<label class="option" for="edit-options-group-info-group-items-3-value-type-offset">An offset from the current time such as "+1 day" or "-2 hours -30 minutes" </label>

The first radio button valued "date" is incorrectly checked.

Dave Kopecek’s picture

Followup to #8 - For those of you playing along at home:

I think the UI issue above is caused in views_handler_filter.inc at either 951 or 959. Looks like there's no provision for radio buttons. I'm guessing something similar is affecting the actual filter as well.

okeedoak’s picture

I'm having the same problem with date fields as described in #7 specifically point 3. I did notice that if you remove all the table rows from inside of grouped filters and then add one back that the input box(s) for the date does show up. But the filter won't save. Three errors appear, one for each of the removed rows: "The title is required if value for this item is defined."

emilekott’s picture

I had the problems described above when adding a grouped date filter for the post date field

It had 3 values:
Within 1 day (greater than -1 day)
Within 3 days (greater than -3 days)
Within 7 days (greater than -7 days)

It didn't work as expected.

I then enabled the Date API and Date Views Modules and it worked as expected.

Is this just a dependency issue?

okeedoak’s picture

Those two modules were already on when I experienced my issues.

emilekott’s picture

I can confirm that although this now works on one view, it is broken as before on another view on the same site.

Mediaworks’s picture

i am having the same issue. the relative fields box does not show when using a group filter for a date. i also get the same effect as above when i remove them all and add a new option. it will show then but as soon as i save or do anything else it reverts back.

mikkelwf’s picture

Same problem here

djween’s picture

I hope I am posting this 'fix' in the right issue.
The following is for those having issues with exposed grouped filters where offset option is not saving.

It is not working for me either but here is how I made it work...

1. first with single filter, select the offset radio button
2. save it (click apply)
3. go back in to the filter
4. now select grouped filter
5. the offset radio buttons should be marked now
6. when you save the filter (click apply) it should stick now!

I don't think this is intended behavior but it works for me for now.

szt’s picture

Priority: Normal » Major

Yes, for a temporary workaround I confirm #16.
You cannot set the radiobuttons for the groupped filters, because it inherits the simple filter's settings for all the options.
So all of the options inherits the same settings, and you can't mix it.
Set to major, because it's a really unusable function at this state (you never check a Save button if it really saved the settings).

jlyon’s picture

#16 allowed me to save the grouped filter options, however, no matter what I select the WHERE clause in the SQL that is generated only uses the values for the first option.

For example, I have the following group_items:

$handler->display->display_options['filters']['field_profile_dob_value']['group_info']['group_items'] = array(
  1 => array(
    'title' => 'Under 18',
    'operator' => 'between',
    'value' => array(
      'value_group' => array(
        'value_choose_input_type' => 'relative',
        'value' => NULL,
        'default_date' => 'now -18 years',
      ),
      'min_group' => array(
        'min_choose_input_type' => 'relative',
        'min' => NULL,
        'default_date' => 'now -18 years',
      ),
      'max_group' => array(
        'max_choose_input_type' => 'relative',
        'max' => NULL,
        'default_to_date' => 'now',
      ),
    ),
  ),
  2 => array(
    'title' => '18 +',
    'operator' => 'between',
    'value' => array(
      'value_group' => array(
        'value_choose_input_type' => 'relative',
        'value' => NULL,
        'default_date' => 'now -18 years',
      ),
      'min_group' => array(
        'min_choose_input_type' => 'relative',
        'min' => NULL,
        'default_date' => 'now -200 years',
      ),
      'max_group' => array(
        'max_choose_input_type' => 'relative',
        'max' => NULL,
        'default_to_date' => 'now -18 years',
      ),
    ),
  ),
);

No matter which option I select (Under 18 or 18+), the SQL code that is generated is for the Under 18 option (the first one):

AND (DATE_FORMAT(STR_TO_DATE(field_data_field_profile_dob.field_profile_dob_value, '%Y-%m-%dT%T'), '%Y-%m-%d') >= '1994-11-28' AND DATE_FORMAT(STR_TO_DATE(field_data_field_profile_dob.field_profile_dob_value, '%Y-%m-%dT%T'), '%Y-%m-%d') <= '2012-11-28') ))

I am using views-7.x-3.5 and date-7.x-2.6 (for date_views).

jlyon’s picture

Update to #18: Changing the operator from Is Between to Is Greater than and Is Less Than seems to work. This solves my issue for now, however the filters are still broken if you want to use the In Between operator.

supradhan’s picture

Hi,

Is there any solution or workaround? I am having strange problem. I can select 'Select a date' or 'Relative date' option but there is no option to put relative date or select date from.
Screen shot

Sk8erPeter’s picture

@CIsSharp : your screenshot can not be seen (403 Forbidden). Why don't you upload it here?

Jason Dean’s picture

@CIsSharp: no there is no solution, only the possible workarounds suggested above (#16 #19).

The inability to select a date or relative date is exactly the problem. Right now, I don't think you can rely on using Views grouped filters with date field.

dagmar’s picture

Status: Active » Postponed (maintainer needs more info)

Could somebody confirm that if this problem is only related to fields provided by 'Date' module or also happens with core date values?

tchurch’s picture

Status: Postponed (maintainer needs more info) » Active

#16 only works for date fields that are part of core because the "offset" radio button isn't an option for date module related fields.

I tried with the "Content: Post date" field (a core field) and it seemed to work (although my date ranges didn't show a result but I expected that).

It's only a problem for date module related dates.

dawehner’s picture

It seems to be that the date module then sadly has to fix some of it's handlers?

tchurch’s picture

I will raise an issue with them and refer to this one and see what they say.

tchurch’s picture

supradhan’s picture

FileSize
203.5 KB

@Sk8erPeter: I have attached in this post.
@pushka: Thanks for you help. Can you tell me where to put the code of #18. I mean in any hooks or...?

View exposed filter problem

Thank you.

kclarkson’s picture

I too am confirming the same issue as @ClsSharp.

I am not given an option to enter a relative date.

GaxZE’s picture

The relative date is being hidden.

Even if I manually unhide this - I'm unable to save my values.

ydahi’s picture

It seems that most of us are trying to build an age-based filter. After doing some looking around I found two possible alternatives:

1. using the computed field module to calculate the age as described in http://drupal.org/node/420932 (for nodes) and here (for user profiles).

2. using the birthdays module

Still would like to see this work natively with views and date.

kclarkson’s picture

Yes I hope this goes into views for sure :)

dagmar’s picture

I'm quite sure this belongs to date module.

aenaon’s picture

subscribe

windmaomao’s picture

+1, i have the same issue as #28, i wonder why the field is hidden ?

windmaomao’s picture

similar like #18, if i change the view to include group options, it still doesn't work on on the front-end.

  $handler->display->display_options['filters']['field_dispense_duets_value']['id'] = 'field_dispense_duets_value';
  $handler->display->display_options['filters']['field_dispense_duets_value']['table'] = 'field_data_field_dispense_duets';
  $handler->display->display_options['filters']['field_dispense_duets_value']['field'] = 'field_dispense_duets_value';
  $handler->display->display_options['filters']['field_dispense_duets_value']['operator'] = '<=';
  $handler->display->display_options['filters']['field_dispense_duets_value']['exposed'] = TRUE;
  $handler->display->display_options['filters']['field_dispense_duets_value']['expose']['operator_id'] = 'field_dispense_duets_value_op';
  $handler->display->display_options['filters']['field_dispense_duets_value']['expose']['label'] = 'Dispense Due Date (field_dispense_duets)';
  $handler->display->display_options['filters']['field_dispense_duets_value']['expose']['operator'] = 'field_dispense_duets_value_op';
  $handler->display->display_options['filters']['field_dispense_duets_value']['expose']['identifier'] = 'field_dispense_duets_value';
  $handler->display->display_options['filters']['field_dispense_duets_value']['expose']['remember_roles'] = array(
    2 => '2',
    1 => 0,
    4 => 0,
    5 => 0,
    6 => 0,
  );
  $handler->display->display_options['filters']['field_dispense_duets_value']['default_date'] = '15 minutes';  
  $handler->display->display_options['filters']['field_dispense_duets_value']['is_grouped'] = TRUE;
  $handler->display->display_options['filters']['field_dispense_duets_value']['group_info']['label'] = 'Due by';
  $handler->display->display_options['filters']['field_dispense_duets_value']['group_info']['identifier'] = 'field_dispense_duets_value';
  $handler->display->display_options['filters']['field_dispense_duets_value']['group_info']['group_items'] = array(
    1 => array(
      'title' => '15 mins',
      'operator' => '<=',
      'value' => array(
        'type' => 'offset',
        'value' => '+15 minutes',
        'min' => '',
        'max' => '',
      ),
    ),
    2 => array(
      'title' => '30 mins',
      'operator' => '<=',
      'value' => array(
        'type' => 'offset',
        'value' => '+30 minutes',
        'min' => '',
        'max' => '',
      ),
    ),
    3 => array(
      'title' => '1 hour',
      'operator' => '<=',
      'value' => array(
        'type' => 'offset',
        'value' => '+1 hour',
        'min' => '',
        'max' => '',
      ),
    ),
    4 => array(
      'title' => '1 day',
      'operator' => '<=',
      'value' => array(
        'type' => 'offset',
        'value' => '+1 day',
        'min' => '',
        'max' => '',
      ),
    ),
    5 => array(
      'title' => '1 month',
      'operator' => '<=',
      'value' => array(
        'type' => 'offset',
        'value' => '+1 month',
        'min' => '',
        'max' => '',
      ),
    ),
  );
kclarkson’s picture

Can anyone confirm whether this is a date module issue or if this a views group filter issue ?

alinouman’s picture

subscribing same issue. Thanks # 19. You solved the problem little bit.

xcel’s picture

#16 allowed me to do what I want in both views preview and front-end.

Thank to the forum users !

kclarkson’s picture

It appears as though we still need a solution that will fix the error.

The issue workaround in 16 still does not help you if you need a Previous or Upcoming Events filter.

noahadler’s picture

Subscribing. Using Chrome developer tools to show the hidden fields ("jQuery('.form-type-date-select').show()" in the console) lets me enter dates and save them, but the affect of changing the filter when looking at the view is absolutely nothing.

The relevant saved code, from views export:

$handler->display->display_options['filters']['field_time_value']['group_info']['group_items'] = array(
  1 => array(
    'title' => 'Thursday, April 18',
    'operator' => '=',
    'value' => array(
      'value_group' => array(
        'value_choose_input_type' => 'date',
        'value' => '2013-04-18',
        'default_date' => '',
      ),
      'min_group' => array(
        'min_choose_input_type' => 'date',
        'min' => NULL,
        'default_date' => '',
      ),
      'max_group' => array(
        'max_choose_input_type' => 'date',
        'max' => NULL,
        'default_to_date' => '',
      ),
    ),
  ),
  2 => array(
    'title' => 'Friday, April 19',
    'operator' => '=',
    'value' => array(
      'value_group' => array(
        'value_choose_input_type' => 'date',
        'value' => '2013-04-19',
        'default_date' => '',
      ),
      'min_group' => array(
        'min_choose_input_type' => 'date',
        'min' => NULL,
        'default_date' => '',
      ),
      'max_group' => array(
        'max_choose_input_type' => 'date',
        'max' => NULL,
        'default_to_date' => '',
      ),
    ),
  ),
  3 => array(
    'title' => 'Saturday, April 20',
    'operator' => '=',
    'value' => array(
      'value_group' => array(
        'value_choose_input_type' => 'date',
        'value' => '2013-04-20',
        'default_date' => '',
      ),
      'min_group' => array(
        'min_choose_input_type' => 'date',
        'min' => NULL,
        'default_date' => '',
      ),
      'max_group' => array(
        'max_choose_input_type' => 'date',
        'max' => NULL,
        'default_to_date' => '',
      ),
    ),
  ),
);
sinn’s picture

It is date's issue.

Patch on the http://drupal.org/node/1876168#comment-7234206 fixes exposed group filter on a front end.

sawtell’s picture

I'm having issues with group filters when using taxonomy terms so I don't think it's limited to date fields. Behaviour is correct when selecting single filter.

spessex’s picture

I appear to be having the same problem when exposing filters for content post date. It just doesn't appear to work for me. It just gives a blank result.

I have the following:

Views
7.x-3.5

Date Views
7.x-2.6

Date
7.x-2.6

Wtower’s picture

The problem is with core date values. I experience the same issue and I am not using the Date module whatsoever.

Workarounds #16 and #19 were good but unfortunately not enough for my case. What I've done is that I ended up creating separate blocks with pre-defined date filters (not exposed). I needed 4 of them anyway (last day, last week, last month, all). I turned them all on for the specific pages I needed it, and then I used jQuery to attach them to a specific div in the page, and to create a set of buttons to hide/show the appropriate view block. If anyone is interested I can post the jQuery code.

xcession’s picture

I too am having problems using the 'offset' method when doing an exposed, grouped filter.

I want to allow users to choose by posts from 'last week', 'last month', 'last year' but use of values such as "-7 days" just results in the pertinent part of the query reading:

AND (node.created >= -86400)

...which is clearly useless as every unix timestamp is by definition greater than -86400!

I've tried alternative values like "CURRENT_TIMESTAMP() -7 days", "NOW() -7 days" etc, but nothing works.

xcession’s picture

Solved my problem

I've discovered that #16 solves the problem of offset dates too, not just the issue of keeping the right radio button checked.

If you're having trouble creating an exposed Group Filter with offset dates, for example: Content from: 'last week', 'last month', 'last year' you first have to create a Single Filter in which you specify just one of those dates from the group. It doesn't matter which, say "last week" or in other words, greater than or equal to the offset date "-7days". Save everything. Then change the filter to be Grouped. The UI will duplicate the one filter value you just input into the first 3 groups of fields. Change them as appropriate and you'll find it's fixed.

Not only will the radio button "An offset from the current time..." remained checked as #16 suggests, but the offset dates will also work where previously they didn't.

supradhan’s picture

Hi xcession,

Will this work with Date module? I am not succeeding to achieve the result. :-( I am not even seeing radio button as mentioned in 1st step of #16. (1. first with single filter, select the offset radio button)

jakraska’s picture

The workaround posted in #16 also fixed the issue for me where it was not saving the 'offset' value type when using grouped filters

Exploratus’s picture

These solutions do not work with date field module fields, only core fields.

No Sssweat’s picture

Version: 7.x-3.5 » 7.x-3.7

not working with 7.x-3.7

I get an error on my site saying,

Error message An illegal choice has been detected. Please contact the site administrator
Exploratus’s picture

It would really be great if this was resolved. It's impossible to use group filters with a date field, which really limits many of my search options.

hefox’s picture

Adding

$handler->display->display_options['filters']['created']['group'] = 1;

to my view export and refreshing (default, non-overriden) fixed my issue

NIKS_Artreaktor’s picture

$handler->display->display_options['filters']['created']['group'] = 1;

it is universal ?

or I have to write it for individual field?

hefox’s picture

Individual filter, 'created' was the field I was using

Exploratus’s picture

Will #53 only work with core fields, or with date fields as well?

kyuubi’s picture

Has anyone got a fix, that will affect date fields? All of the listed ones here and on the Date queue don't work for me.

bradjones1’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)

This filter is provided by date module - there's work underway over there on #1876168: Exposed grouped filter for date not working

gmariia’s picture

Dears, I have tried all methods mentioned above for my drupal7, views 3 and date module, but nothing works so far... Are there any fresh ideas or custom modules to solve the issue? I just need to filter content by grouped filter options this week, this month, this year, so simple that is just stupid to stuck with it... I would really appreciate any help!!!

dodlhuat’s picture

I'm looking for the exact same solution as gmariia.

blazey’s picture

Hey, you might want to take a look at https://www.drupal.org/node/1876168#comment-9430357.

fbela’s picture

hey, i use datepopup on my views i want to exposed filter date created is greater than or equal /is less than or equal... "is greater than equal work fine, but 'is less than or equal' not working display like 'is less than'

any suggestion thanks