I am unable to change the date format for an exposed field in views. I am using BEF datepicker popup. I overrode the jquery settings to get it to enter a UK date in the dd-mm-yy format but because views is expecting it in mm-dd-yy form, the results of the filter are wrong.
This problem is addressed in this discussion https://www.drupal.org/node/1409120 but supposedly has been fixed for other people in Date 7.x 2.x. I am using BEF 7.x-3.0-beta4, Date 7.x-2.9-alpha1+2-dev, and Views 7.x-3.8, and the problem isn't fixed. I can't see any extra options in the view settings or in the config menu to change the date format.
The field name is field_activity_date_time and I have created a custom module with the following code, based on other stackoverflow suggestions (I don't have a max and min field, just a single date)
function hook_form_views_exposed_form_alter(&$form, &$form_state) {
if($form['#id'] == 'views-exposed-form-test-page') {
$form['field_activity_date_time']['#date_format'] = 'd/m/Y';
}
}
}
I have tried a number of different possibilities for the array key, such as 'activity_date_time', and 'views_field_activity_date_time', none of which worked. This date field is coming from a CiviCRM table which may be why the other suggestions haven't worked, but it feels to me more of a drupal problem than a civicrm one.
as suggested by harsh in the comments, I have used a different hook, but the problem still persists...
function HOOK_form_alter(&$form, &$form_state, $form_id){
if ($form_id == 'views_exposed_form' && $form_state['view']->name == 'test' && $form_state['view']->current_display == 'page') {
$form['activity_date_time']['#date_format'] = 'd/m/Y';
echo '<pre>';
print_r($form);
echo '</pre>';
}
}
This gave me the following
Array
(
...
[activity_date_time] => Array
(
[#type] => textfield
[#size] => 30
[#default_value] =>
[#attributes] => Array
(
[class] => Array
(
[0] => bef-datepicker
)
)
[#date_format] => d/m/Y
)
)