Reputation: 299
I know how to gray out the weekends on the jQuery Datepicker by instantiating it like this:
$('.calendar').datepicker({ beforeShowDay: $.datepicker.noWeekends });
The Datepicker also automatically selects the current date, so if the current date happens to be on a weekend, nothing is selected.
How can I make it select the next weekday if the currentdate falls on a weekend?
Thanks a lot!
Al
Upvotes: 0
Views: 2309
Reputation: 630379
You can loop through and find the next valid date based on whatever beforeShowDay
function you're using and set the defaultDate
property to the result, like this:
var sd = new Date();
for(var i = 0; i < 7; i++) {
if($.datepicker.noWeekends(sd)[0]) break; //found a valid day, hop out
sd.setDate(sd.getDate() + 1); //move to the next day
}
$('.calendar').datepicker({
beforeShowDay: $.datepicker.noWeekends,
defaultDate: sd
});
Here's a demo that works for today (otherwise you could only see it work on weekends :)
Upvotes: 2