I want to have views exposed filter on node created field with popup. I've installed date_popup, the popup appears but I'm looking for a way to restrict it to only year and month.

enter image description here

I tried the following solutions but no success.

function HOOK_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  if( $form['#id'] == 'views-exposed-form-news-page-1') {
    $form['created']['#date_format'] = 'm-Y';
    $form['created']['#date_date_format'] = 'm-Y';
    $form['created']['value']['#date_format'] = 'm-Y';
    $form['created']['value']['#date_date_format'] = 'm-Y';
    $form['date_needed'] = [
      '#type' => 'date',
      '#title' => 'test',
      '#date_date_format' => 'm/Y',
      '#date_format' => 'm/Y',
  return $form;

enter image description here

  • I don't think there is a way yet to adjust date granularity for an exposed filter. However, there is a patch to introduce it.
    – sonfd
    Commented Nov 26, 2019 at 22:41
  • @sonfd thank you for your attention. I'll try it. but waiting for other answers.
    – Yuseferi
    Commented Nov 26, 2019 at 22:51
  • did you try '#datepicker_options' => array( 'dateFormat' => date_popup_format_to_popup('m-Y'), ), ?
    – Ziftman
    Commented Nov 26, 2019 at 22:55
  • Have you seen this post, drupal.stackexchange.com/questions/263311/…
    – user72672
    Commented Nov 26, 2019 at 22:56
  • Confused by your screenshots. The first looks like a Javascript popup (from the date_popup module?). The second looks like the native Chrome date picker. If you do <input type="date"> then you will always get the native date picker. You need to do <input type="text"> if you want to override this behavior. But, I am not familiar with the date_popup to know how to integrate it with Form API.
    – mpdonadio
    Commented Nov 27, 2019 at 14:39

1 Answer 1


You'll need a external library to do that. Something like jQuery UI Month Picker Plugin and you'll probably will need to use a textfield rather than date.


Use the Month Year module

This module provides a month year field type.

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.