0

I am developing a custom module, where I need to disable future dates in the date pop-up. How can I do this?

0

This can be achieved by adding an attribute max

$form['date'] = [
  '#title' => $this->t('Date'),
  '#type' => 'date',
  '#attributes' => [
    'type' => 'date',
    'min' => '-25 years',
    'max' => 'now',
  ],
  '#date_date_format' => 'd/m/Y',
];

Reference: https://api.drupal.org/comment/61733#comment-61733

-2
$form['birthDate'] = array(
        '#type' => 'date_popup',
        '#title' => t("Birth Date"),
        '#date_format' => 'Y-m-d',
        '#date_year_range' => '-100:0',
        '#datepicker_options' => array('maxDate' => '-1 day' ),
        '#date_label_position' => 'invisible',  
        '#required' => TRUE,
    );  
  • Why did you post the code here? – Pierre.Vriens Aug 8 '17 at 7:19
  • Can you expand on how this addresses the problem? Thanks. – mpdonadio Aug 8 '17 at 22:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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