18

I'm using Drupal 7 with views 3.

I have used an exposed filter for a date field and I want to provide option to choose date from datepopup for date filter? How can I do this?

3 Answers 3

14

The Better Exposed Filters module integrates with the date type fields, including the date popup. You can use this module to easily add an exposed filter with the date popup.

There are some known issues with BEF's integration with the date module; from the module page:

(Note: Support for fields supplied by the Date module is a little funky until #392836: Exposed Date filter format (in Views) and/or #502824: Date format in exposed filter (views) are resolved).

Also, you can only add this type of filter to entity fields at the moment, not properties. There are various discussions going on about this.

2
  • 4
    Note that the module which enables this on BEF is date_views.
    – cherouvim
    Commented Jul 4, 2012 at 12:43
  • Some more details on how to implement this would be helpful.
    – doub1ejack
    Commented Oct 27, 2013 at 16:59
13

You don't need BEF to get popup calendar with exposed view filters. You just need "Date pop up" and "date views" submodules.

  • When creating new exposed filter in "Filter" dropdown select "Date"
  • then choose the Date filter
  • choose a date field (for instance "Date: Date (node)")
  • in extra settings config , in the "Date selection form element" section select "Popup"
  • follow other regular steps.
0

Drupal 9/10 I Just did a normal exposed filter (for a timestamp / date) field Selected between dates left all defaults blank then added (in a module)

/**
 * Implements hook_form_ID_alter().
 */
function SOMEMODULE_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $view_ids = ['my_view_id'];
  if ($form_id === 'views_exposed_form') {
    $view = $form_state->getStorage('view');
    if (!empty($view) && in_array($view['view']->id(), $view_ids)) {
      $form['field_timestamp_wrapper']['field_timestamp']['min']['#type'] = 'date';
      $form['field_timestamp_wrapper']['field_timestamp']['max']['#type'] = 'date';
      $form['field_timestamp_wrapper']['field_timestamp']['min']['#title'] = t('From');
      $form['field_timestamp_wrapper']['field_timestamp']['max']['#title'] = t('To');
    }
  }
}

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.