I have a Date field with granularity of Month, Year in Exposed filter. Everything is working fine, but the month and year default values are shown as "-Month" and "-Year".

Let me know how to alter the form to remove the "-" from Month and Year filter.

enter image description here


1 Answer 1


One method would be to alter the exposed filter form date_select form element. Add this to a custom module:

 * Implements hook_form_alter().
function MYMODULE_form_views_exposed_form_alter(&$form, $form_state, $form_id) {
   $form['#after_build'][] = 'views_exposed_form_date_select_alter';

 * Alter the label option on Year/Month selector
function views_exposed_form_date_select_alter($form, &$form_state) {
   $form['MY_DATE_FIELD']['year']['#options'][''] = 'Year';
   $form['MY_DATE_FIELD']['month']['#options'][''] = 'Month';
   return $form;
  • The form array for my date field looks like below, let me know which value to alter. I think month and year options are not directly accessible. Array ( [#tree] => 1 [value] => Array ( [#title] => [#type] => date_select [#size] => 20 [#default_value] => [#date_format] => m/Y [#date_label_position] => within [#date_year_range] => -1:+10 [#process] => Array ( [0] => date_select_element_process ) [#prefix] => [#suffix] => ) ) Its not directly accessible as this ['#options']
    – abhiklpm
    Apr 21, 2015 at 14:48
  • 1
    Ah, its using a date_select form element (should have thought about that). You'll need to alter it after date is finished building it. Try the solution above with the correct name of your date selector element.
    – Shawn Conn
    Apr 21, 2015 at 20:32
  • Thank you exactly what I needed, we also need to return the form. I have edited to included that also.
    – abhiklpm
    Apr 22, 2015 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.