jQuery UI Datepicker - allow only certain weekdays

Pedro Gil picture Pedro Gil · Dec 19, 2010 · Viewed 15.1k times · Source

I'm using jquery UI datepicker on a huge project and I realize now that I'll need to allow only certain weekdays on some areas. I read their documentation and didn't find anything about it.. I know that there are some datepickers scripts for jq which can do this but I don't want to use any additional script for this if it's possible. Anyone know any workaround for this? Maybe I'm misunderstood anything in their documentation?

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

Thanks in advance for help, Cheers Pedro

Answer

Jan Thomas picture Jan Thomas · Feb 15, 2012
$( ".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;
});