JQuery UI Datepicker - allow only specific business days

I am using jquery UI datepicker in a huge project, and now I understand that I need to allow only certain workdays in some areas. I read their documentation and found nothing about it. I know there are datepickers scripts for jq for jq, but I do not want to use any additional scripts for this, if possible. Does anyone know about this? Maybe I misunderstood something in their documentation?

NOTE: an example of the desired behavior: http://codeasp.net/blogs/raghav_khunger/microsoft-net/1088/jquery-datepicker-disable-specific-weekdays

Thanks in advance for your help, cheers Pedro

+6
jquery jquery-ui jquery-ui-datepicker datepicker uidatepicker
source share
5 answers
$( ".datepicker.future" ).datepicker('option','beforeShowDay',function(date){ var td = date.getDay(); var ret = [(date.getDay() != 0 && date.getDay() != 6),'',(td != 'Sat' && td != 'Sun')?'':'only on workday']; return ret; }); 
+7
source share

@ Jan Thomas forgot to add the td variable. The correct code is:

 $( ".datepicker.future" ).datepicker('option','beforeShowDay',function(date){ var td = date.getDay(); var ret = [(date.getDay() != 0 && date.getDay() != 6),'',(td != 'Sat' && td != 'Sun')?'':'only on workday']; return ret; }); 
+5
source share
 $('selector').datepicker({ beforeShowDay: $.datepicker.noWeekends // disable weekends }); 
+4
source share

From the docs:

beforeShowDay: The function takes a date as a parameter and should return an array with [0] equal to true / false, indicating whether this date is selected, [1] equal to the name (s) of the CSS class or '' for default presentation, and [2 ] an additional tooltip for that date. It is called for every day in the datepicker before displaying it.

An example can be found here:

http://codeasp.net/blogs/raghav_khunger/microsoft-net/1088/jquery-datepicker-disable-specific-weekdays

+2
source share

Jean Mallet's answer ( beforeShowDay: $.datepicker.noWeekends ) is simple and elegant.

However, if you are already calling a function using beforeShowDay (as I was in my case), here is how you can disable certain days of the week (in this case, Sunday and Saturday), chained along with the rest of your function:

 beforeShowDay: function (date) { /* your other function code here */ if (date.getDay() > 0 && date.getDay() < 6) { return [true, '']; } else { return [false, '']; } } 

enter image description here

0
source share

All Articles