1

I need to personalize some settings in the date popup calendar in a date field. This is the documentation for the popup calendar used in the Drupal date field: http://api.jqueryui.com/datepicker/

I would to configure for example, the minDate property, to set a minimum selectable Date, according the documentation this is the code:

$( ".selector" ).datepicker({
  minDate: new Date(2007, 1 - 1, 1)
});

But... How and where do I type it in a custom module? It looks javascript, but I don't know how to make this code work for my date form element.

1 Answer 1

1

You can add it with #datepicker_options, e.g.:

$form['date'] = [
  '#type' => 'date_popup',
  // ...
  '#datepicker_options' => [
    'minDate' => 0,
  ],
];
10
  • Clive, I think your code is good for adding a new form element. What is the code to add the property in an existent form element?
    – bunset
    Commented Feb 11, 2017 at 16:57
  • Very similar, just find where the element you want to change is in the form array and use something like $form['foo']['#datepicker_options'] = ...
    – Clive
    Commented Feb 11, 2017 at 23:25
  • I have tried multiple #datepicker_options in different places and it doesn't work on my popup calendar. I want to try with javascript. How can I add the javascript code programmatically from my module?. I need programmatically because the property I have to change is a variable value in my specific use case.
    – bunset
    Commented Feb 12, 2017 at 5:08
  • 1
    Adding/managing JS is covered at length in the docs; that page should everything you need from the sounds of your requirements, but if not try searching this site. For example drupal.stackexchange.com/questions/12851/… has some good supplementary info. Personally I'd be tempted to persevere with the form alter approach, it's likely you just haven't found the right array element yet. Also: drupal.stackexchange.com/questions/27767/…
    – Clive
    Commented Feb 12, 2017 at 17:41
  • 1
    Yes, but I can't tell you what that is you need to inspect the code and see what classes your theme is attaching to the input for you to target
    – Clive
    Commented Feb 13, 2017 at 7:45

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.