4

Given this form

  $form['date'] = array(
  '#prefix'=>t('When do you want to start the featured campaign?'),
  '#date_format' => 'Y-m-d',
  '#date_year_range' => '0:+1',
  '#type' => 'date_popup',
  '#weight'=>0
  );

is there a way to display only future dates in the javascript popup ? I can't seem to figure it out. Thanks alot.

3 Answers 3

6

Custom datepicker options are now supported (as of Date module version 7.x-2.6) by setting the necessary values with #datepicker_options. Alex's use case of a custom form element to display only future dates would look like this:

$form['date'] = array(
  '#prefix'=>t('When do you want to start the featured campaign?'),
  '#date_format' => 'Y-m-d',
  '#date_year_range' => '0:+1',
  '#type' => 'date_popup',
  '#weight'=>0,
  '#datepicker_options' => array('minDate' => 0),
);
1

Date use Jquery DatePicker: https://jqueryui.com/datepicker/#min-max

Then, We must do that from javascript:

  $(function () {
      $("#myIdinputDatePicker").datepicker({ minDate: -0, maxDate: "+1M +10D" });
  });

That's it, leaving the Drupal World.

0

As far as I know by default you do not have such option. The easiest way would be just to check it in validate function, and return an error if selected date is not from future.

On the other hand, a quick Google search returned for example this question - how to restrict the user to enter only today to future dates. using datepicker - however you would need to test for yourself if it really works...

0

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.