Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hello, i'm trying to set the default date as today's date for my exposed filter.
But i can't find how to do it (i don't want to use relative value, so i don't see where to set the default value?)
I've attached a screenshot of the filter windows...
I want to display nodes of a certain type that have a date field called dateEvent.
The node displayed should have the date set in the dateEvent field greater or equal to today's date by default. The user can edit the date set in the filter (which is a text filter)
Comment | File | Size | Author |
---|---|---|---|
dateFilter.png | 25.48 KB | WilliamB |
Comments
Comment #1
WilliamB CreditAttribution: WilliamB commentedMy field is called datepickerHidden.
I've overloaded the form_alter method
To put the date in the d/m/Y format and add a default value, however i've issue with the pager with is built: http://mysite/mypage?datepickerHidden[value]=2012-01-24&page=1
2 issues:
- the link is missing [date] after datepickerHidden[value] which makes views not take into account the value.
- The date is using the wrong format: 'Y-m-d' instead of 'd/m/Y' that i could find a work around but not the first point.
when i enter today's value manualy in the filter, the pager link is built correctly:
http://mysite/mypageagenda?datepickerHidden[value][date]=24/01/2012&page=1
The bug sorta occurs also in the backoffice.
If i enter today's date in the exposed field and i submit, the list will display the 5 first correct results.
However if i click on the pager : http://mysite/mypage#overlay=admin/structure/views/nojs/preview/agenda/p...
The list suddenly display older nodes, and the pager goes from 2 pages (6 entries should be returned, 5 by page) to 5+ pages (bringing back ALL nodes of that type regardless of the value of their date field)
Thanks in advance for any help....
Comment #2
KarenS CreditAttribution: KarenS commentedYou don't need to write any custom code. There are two options in the filter settings: "Select a date" to select a specific date, or "Enter a relative date" which will give you a textfield where you can use things like 'now'.
Comment #3
WilliamB CreditAttribution: WilliamB commentedThe thing is, it's an exposed date filter.
I want the user to be able to write another date in a dd/mm/yyyy format (not a relative date)
And i want the default date to be equal to today's date.
How can this be done?
Comment #4
KarenS CreditAttribution: KarenS commentedSet the default as a relative date (for 'today'). If you make it an exposed filter the user will still get the option to choose a date, the default is just the ... default.
Comment #6
WilliamB CreditAttribution: WilliamB commentedKarenS, i'm sorry for reopening this, but even with default date being relative equal to now, the pager links still misses [date] after datepickerHidden[value] which makes views not work correctly.
If i select a date then the [date] bracket is added and works fine but by default it's missing, even in the back office:
http://www.mysite.com/mypage/#overlay=admin/structure/views/nojs/preview...
If i add [date] before [value] the page would work fine, or if i remove the value of the date after the =, 2012-05-09, it works also fine ...
Comment #7
WilliamB CreditAttribution: WilliamB commentedComment #8
drakythe CreditAttribution: drakythe commentedI'm having this issue as well, with Views 3.5 and date 2.6. I have an exposed filter with a default date of "now" -- if I do not click the "apply" button however, the link to the next page does not contain the correct filters.
http://mysite.com/shows?field_show_attr_date_date_value[min][year]=2013&field_show_attr_date_date_value[min][month]=1&field_show_attr_date_date_value[min][day]=25&field_show_attr_date_date_value[max][year]=2014&field_show_attr_date_date_value[max][month]=1&field_show_attr_date_date_value[max][day]=25&field_show_attr_categories_tid=&title_1=&field_show_attr_venue_related_nid=All&title=&page=1
Is what happens if I hit "apply" and then change the pager.
http://mysite.com/shows?field_show_attr_date_date_value[min]&field_show_attr_date_date_value[max]&field_show_attr_categories_tid=&title_1=&field_show_attr_venue_related_nid=All&title=&page=1
Is what I get if I do not click the "apply" button.
Also, this issue seems similar, but I'm not sure if it is a duplicate or not...
#1271726: Issue with pager and exposed text date filter in views
Comment #9
Priti197 CreditAttribution: Priti197 commentedI am facing the same issue, if default value is set in exposed date filter pagination don't work properly. Any solution, please help!
Comment #10
ufku CreditAttribution: ufku commentedEven the filter works as expected the default value of a text field appears empty in the initial form. (Submitted values appear as expected)
Similar to date_popup_element_value_callback() being used for popup element, I guess, date_text_element_value_callback() should be called by date_text_element_process() while assigning the field value.
$element['date']['#value'] = isset($element['#value']['date']) ? $element['#value']['date'] : date_text_element_value_callback($element)['date'];
No patch, sorry.