I'd like to be able to restrict selectable dates within the datepicker popup. Specifically I'd like to disallow selecting weekend days.

This is how datepicker does this:

http://stackoverflow.com/questions/501943/can-the-jquery-ui-datepicker-b...

I think I can write a PATCH so date module supports this. I'll try first to make it only an option to disallow weekend day selection. I think the function to start writing this is date_popup_process_date, and also modify the widget form right?

I don't know if a more general option can be implemented.

Anyone thinks this might be useful?

Comments

frixos12’s picture

Any progress with this patch?

frixos12’s picture

As i saw to various jquery examples..

i tried to put this command $("#datepicker").datepicker({ beforeShowDay: $.datepicker.noWeekends }) in the date_popup.js file (i guess)

using this format but nothing happens

switch (datePopup.func) {
case 'datepicker':
$(this)
.datepicker(datePopup.settings)
.addClass('date-popup-init')
$(this)
.datepicker({ beforeShowDay: $.datepicker.noWeekends })
.addClass('date-popup-init')

I am not familiar with JQuery at all so i need to know if my approach is at least right.

thank you

mlyno’s picture

I find to control which dates can be (or more can't be) selected are very usefuul and important. Something was tried on D6 #625264: Improvements to date_popup module

KarenS’s picture

KarenS’s picture

Issue summary: View changes

specify possible start point for patch

vjsutar’s picture

Issue summary: View changes

By Using jQuery for drupal textfield.
Just create textbox field from drupal backend. Then in js file paste the following code.

jQuery(document).ready(function (jQuery) {
    jQuery('#id_of_text_field').datepicker({
        beforeShowDay: enableDates
    });
    function enableDates(date) {
        var day = date.getDay();
        // 0-Sun,1-Mon,2-Tue,3-Wed,4-Thu,5-Fri,6-Sat
        return[(day == 1 || day == 2 || day == 3 || day == 4 || day == 5), ''];
    }
});
mhentry’s picture

Thank you

mhentry’s picture

solideogloria’s picture

This issue should be reopened. Yes, there are other ways to do it with custom jQuery, but the whole point of allowing properties to be passed to the widget is to pass them and have them work. Passing functions to the widget with the intended method does not work at the moment, because they have to be passed as strings.

An easy fix would be to use this patch: https://www.drupal.org/files/issues/date-allow_to_use_beforeShowDay-1143680-23.patch, except that I added the lines inside the select after line 10 of date_popup.js. (This fixes the beforeShowDay property by allowing the stringified function to be evaluated).

Please update the module so that it works for all of the properties out of the box. Thanks.