3

I need to use a pop up date picker from the Date module in the Form API. It's displaying OK, but I want to restrict the user to only have the option of selecting dates that have passed, and not future dates.

How can I achieve this?

Here is my code:

$form['fieldset_one']['date_field'] = array(
  '#weight' => '5',
  '#title' => t('Date of Birth'),
  '#type' => 'date_popup',
  '#date_format' => 'Y-m-d',
  '#date_year_range' => '-80:0',
);

2 Answers 2

0

You can try this approach:

Pass the JS options in '#datepicker_options'

$form['fieldset_one']['date_field'] = array(
  '#weight' => '5',
  '#title' => t('Date of Birth'),
  '#type' => 'date_popup',
  '#date_format' => 'Y-m-d',
  '#date_year_range' => '-80:0',
  '#datepicker_options' => array(
    'maxDate' => 0,
  ),
);

maxDate => 0 should set the maximum date to today. -1 would set it to yesterday.

More info: http://api.jqueryui.com/datepicker/#option-maxDate

0

They are talking about datepicker options here: Customize days that can be clicked on a Calendar popup

Apparently datepicker is quite versatile, with those options you can set max-date, min-date etc.

0

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.