Improvements to date_popup module
| Project: | Date |
| Version: | 6.x-2.x-dev |
| Component: | Date Popup |
| Category: | task |
| Priority: | normal |
| Assigned: | Jorrit |
| Status: | needs review |
I was unsatisfied with the data_popup module and I have extended the module to support more options of the ui.datepicker module. Specifically, I added support to limit the selectable dates using a minimum and maximum day, exclude specific weekdays, exclude specific days and set any other ui.datepicker option from PHP.
The documentation of the date_popup_elements function was appended with the following. This gives a good overview of the things the patch adds:
* #date_date_min
* The minimum selectable date. Give a timestamp or string
* that is parseable by strtotime.
*
* #date_date_max
* The maximum selectable date. Give a timestamp or string
* that is parseable by strtotime.
*
* #date_weekday_disable
* Unselectable weekdays. Give an array of integers, where 0 is
* Sunday, 1 is Monday, etc.
*
* #date_day_disable
* Unselectable days. Give an array of timestamps or strings
* that are parseable by strtotime.
*
* #date_datepicker_attributes
* Additional ui.datepicker attributes can be supplied in this
* attribute. See http://docs.jquery.com/UI/Datepicker
* Example:
* array('changeFirstDay' => FALSE)I have also added server-side validation for these values, so even submitting the form with invalid values is not possible. Also, I've updated the javascript and CSS files to the latest jQuery UI 1.6 versions, because the supplied files are too old: the appearance is much better with the new files.
I have not tested all aspects fully, I hope people wanting these features test this patch. It was created using the latest version of the 6.x-2.x branch. I specifically refer to issues #335933: Easy way to make days unselectable and #510464: more control over settings.
The work in this patch is not entirely finished, but I think it's a good start to begin enhancing this submodule.
| Attachment | Size |
|---|---|
| date_popup.patch | 141.41 KB |

#1
+1 for this solution
#2
Small update for IE
#3
Thanks a million for taking this on!
I tried it with this as my form field:
$form['datepicker'] = array('#type' => 'date_popup',
'#title' => 'Date Needed',
'#date_weekday_disable' => array(0,1,2),
'#date_date_min' => time(),
'#date_date_max' => time() + 60*60*24*12,
'#date_day_disable' => array(time() + 60*60*24*9, time() + 60*60*24*10),
);
The #date_date_min and #date_date_max worked like a charm but nothing the #date_weekday_disable and #date_day_disable did nothing for me?
I am going to reinstall date module and reapply the patch to be sure.
If this works, it will be so incredibly helpful!
#4
Reapplied the patch again. Tried changing to generic zen theme. Nothing seems to work.
Do you want me to try something else?
Just let me know.
#5
The day disable part is not very refined: the timestamps must match exactly in PHP and in Javascript. Why weekday disable doesn't work I don't know. Are you able to submit invalid dates? The PHP part also does validation.
#6
I can confirm that the PHP validation is working for day disable and weekday disable.
I can also confirm that everything, including the javascript pop up, works on a new plain vanilla Drupal installation for me.
I had previously tested this with an existing site configuration of a production site that had a lot of other modules installed.
I am looking in to what is breaking it on my existing site. Drupal and all the contrib modules seem to be up to date, but I am looking at it trying to see if is just a bad piece of custom code or if there is another contrib module and/or theme conflicting with the patch.
#7
I must have run the patch wrong? When I copied the date module over from the new Drupal install that was working, and replaced the whole date module on the regular site; everything worked. I have don't know why originally, some stuff seemed to work but not others, but I'm not complaining.
Sorry for the confusion. Great patch!
This is really awesome! I'm going to start moving forward with it.
Is there anything else I can do?
#8
Great improvment done. If you have better knowledge of FAPI and Date Api maybe we can join forces to add this feature too #613614: User-friendly multiple date selection.
#9
I made this patch because I needed the functionality and saw an opportunity to add it quite easily. I do not need the mentioned functionality at this point, so I will not work on that issue.
I shared the patch because I wanted to help other people and when it's committed to the main source, I don't have to maintain a separate patch myself. However, I will not provide support for the patch because I don't have time to do so. I expect people who try out the patch to fix bugs they find themselves and share the improvements here.
#10
This is not required as date will use the jquery_ui's datepicker if you have that module enabled and the latest jquery.ui lib installed. Also the jQuery UI version you have added is not minified and results in far much more code to get downloaded.
As for the patch, thank you. I need this support myself.
For those of us who use date_popup in CCK, it will be required that we can configure this when we edit a field. Could that functionality get added.
Thanks again for your work.
Jordan