Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI Datepicker - allow only certain weekdays

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

like image 370
Pedro Gil Avatar asked Dec 19 '10 18:12

Pedro Gil


2 Answers

@Jan Thomas forgot to add the variable td. 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;
});
like image 126
Fellipe Brito Avatar answered Nov 10 '22 14:11

Fellipe Brito


$( ".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;
});
like image 9
Jan Thomas Avatar answered Nov 10 '22 15:11

Jan Thomas