Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
date-D7-mindate.patch | 1.17 KB | hutch | |
Comments
Comment #1
tsido CreditAttribution: tsido commentedWe have this requirement as well that was solved with a very similar workaround. Would be nice to see this included in the module itself.
Comment #2
tsido CreditAttribution: tsido commentedApparently 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
Comment #3
nightlife2008 CreditAttribution: nightlife2008 commentedI 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.
Works like a charm!
Comment #4
rwaery.11 CreditAttribution: rwaery.11 commented@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.
Comment #5
sebto CreditAttribution: sebto commented#3 works for me. Thanks a lot! without any hack in date module.
Comment #6
sense-designPlease 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.
Comment #7
sarikak CreditAttribution: sarikak commented@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.
Comment #8
yogesh045 CreditAttribution: yogesh045 commentedYou can implement min date and max date like the given code below