1

I have a view and an exposed filter with a date field, I want to make this filter as a date picker, not a text field, I've used Better Exposed Filters but didn't find anything in view, I had used it much time in D7 but In D8 cannot find it in the view exposed form style. So what should I do to use this module

1 Answer 1

5

You can add the jquery date picker in for that page as dependency.

your_theme.libraries.yml

date-picker:
  js:
    script/site-datepicker.js : {}
  dependencies:
    - core/jquery
    - core/jquery.ui.datepicker

site-datepicker.js

Drupal.behaviors.customDatepicker = {
  attach: function (context, settings) {
    jQuery(function () {
      jQuery("#datepicker").datepicker({
        dateFormat: "dd-mm-yy",
        altField: "input[data-drupal-selector=edit-created]",
        altFormat: "yy/mm/dd 23:59:59"
      });
    });
  }
};

views-exposed-form--views-block-name.html.twig

{% if q is not empty %}
  {#
    This ensures that, if clean URLs are off, the 'q' is added first,
    as a hidden form element, so that it shows up first in the POST URL.
  #}
  {{ q }}
{% endif %}

<input id="datepicker" type="text">
<input data-drupal-selector="edit-created" data-msg-maxlength="This field field has a maximum length of 128." name="created" size="30" maxlength="128" aria-invalid="false" type="hidden">
{{ form|without('created') }}

There is also the Date Popup module, for Drupal 8. You can use that module and implement this functionality.

1
  • How to add month and date selector to the calendar? @Himanshu Nov 13, 2019 at 21:44

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