Question

I want to filter the selectable dates on a datepicker. I basically need to filter by work days - i.e. make holidays and weekends not selectable.

I know you can specify dates using a function in the beforeShowDate: and you can also use $.datepicker.noWeekends.

Question is: can you do both?

Was it helpful?

Solution

$.datepicker.noWeekends is a pretty simple bit of code:

function (date) { 
    var day = date.getDay(); 
    return [day > 0 && day < 6, ""]; 
}

Since you're going to have to write up the function for holidays, you can just include this logic in that function too.

OTHER TIPS

Can you do the opposite and have the input what dates are selectable and leave all the rest filtered out?

Yes you can.

i.e. If you only want the user to be able to select Mondays you would add something like:

onlyMondays: function(date){
    var day = date.getDay();
    return [(day == 1), ""]
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top