I have a need to limit the datepicker to only enable days in the future, a hunt through the datepicker docs landed me on the "minDate" option, so I added it to the date_popup module, see the attached patch.
It sets the default to null, eg 'no limit'

I added the following code to my date_popup type:

'#mindate' => "+0",

Now the calendar has all days previous to 'now' disabled and the months too. It does not disable times before 'now' but I can live with that, there does not appear to be an option for that in datepicker.

Files: 
CommentFileSizeAuthor
date-D7-mindate.patch1.17 KBhutch

Comments

tsido’s picture

We have this requirement as well that was solved with a very similar workaround. Would be nice to see this included in the module itself.

tsido’s picture

Apparently the support for this just arrived. The version 7-x.2.6 of the module, that was released just yesterday, seems to address this issue already: see http://drupal.org/node/1143680

nightlife2008’s picture

I solved this problem using the HOOK_date_popup_process_alter(), which is run AFTER the element has been processed, to add the #datepicker_options array.

After adding the options, I just reprocess the element with the proper options set.

function MODULE_date_popup_process_alter(&$element, &$form_state, &$context) {
  if (isset($element['#field']['field_name'])) {
    switch ($element['#field']['field_name']) {
      case 'field_fact_periode': {
        $element['#datepicker_options'] = array(
          'minDate' => "+3D",
        );
        $element['date'] = date_popup_process_date_part($element);
      }
      break;
    }
  }
}

Works like a charm!

rwaery.11’s picture

@nightlife2008, thanks for pointing out the date_popup_process_date_part($element). I was missing that line and caused the datepicker_options not to take effect, even though the array key=>values were updated.

sebto’s picture

Issue summary: View changes

#3 works for me. Thanks a lot! without any hack in date module.

sense-design’s picture

Please keep in mind that this does not validate the form and just modifies the display and usage of the popup. The editor is still able to change the date manually in the textfield by placing the cursor and typing in the date on the keyboard.

For this there is still the need to add a validate hook to the form to prevent saving.

sarikak’s picture

@nightlife2008
As per #3 I can implement the minDate to datepicker, and it works fine but the field names changes from 'Start date' and 'End date' to 'Date'. Can u help me to resolve this issue.

Thanks.

yogesh045’s picture

You can implement min date and max date like the given code below

$form['end_date'] = array(
    '#title' => t('End Date '),
    '#type' => 'date_popup',
    '#default_value' => "",
    '#date_format' => 'd-m-Y',
    '#date_year_range' => '-1:+0',
    '#datepicker_options' => array(
           'maxDate' => '0', // not more than current date
           'minDate' => '2-11-2016' // not more than given date
       ),
  );