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)

dateFilter.png25.48 KBWilliamB
Members fund testing for the Drupal project. Drupal Association Learn more


WilliamB’s picture

My field is called datepickerHidden.

I've overloaded the form_alter method

if (empty($form_state['view']->exposed_input['datepickerHidden'])) { 
	$form_state['input']['datepickerHidden'] = array('value' => array('date' => date('d/m/Y',time())));
$form['datepickerHidden']['value']['#attributes'] = Array ( 'class' => Array ('txt'));			
$form['datepickerHidden']['value']['#date_format'] = 'd/m/Y';

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:

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....

KarenS’s picture

Status: Active » Fixed

You 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'.

WilliamB’s picture

Status: Fixed » Active

The 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?

KarenS’s picture

Status: Active » Fixed

Set 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.

Status: Fixed » Closed (fixed)

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

WilliamB’s picture

Status: Active » Closed (fixed)

KarenS, 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:


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 ...

WilliamB’s picture

Status: Closed (fixed) » Active
drakythe’s picture

Status: Closed (fixed) » Active

I'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.
Is what happens if I hit "apply" and then change the pager.
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

pritimhjn’s picture

I am facing the same issue, if default value is set in exposed date filter pagination don't work properly. Any solution, please help!

ufku’s picture

Title: How can i assign a default value to text date exposed filter? » Default value is not visible in exposed form for Text element
Category: Support request » Bug report
Issue summary: View changes

Even 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.