Reputation: 47
I have a datepicker and I would like to disable the monday following the weekend if it is Saturday or Sunday....is this possible?
Im guessing I have to find a way to:
Any help much appreciated on this
Upvotes: 2
Views: 1232
Reputation: 3688
You can find the current date by making a new date object:
var today = new Date();
Then you can use beforeShowDay
function of datepicker
to disable the following monday as you described with conditionals:
Here is a working fiddle I made: http://jsfiddle.net/MadLittleMods/DfAYY/
var today = new Date(); // Go ahead and change the current day (year, month, day)
// If today is Saturday or Sunday then no Monday for you
function noFollowingMonday(thisDate) {
// Sunday = 0, Saturday = 6;
if(today.getDay() == 0 || today.getDay() == 6)
{
// Monday = 1
// Only Mondays - that are after today - and is the first monday after today
if (thisDate.getDay() == 1 && today.getDate() < thisDate.getDate() && Math.abs(today.getDate() - thisDate.getDate()) < 7)
{
return [false, "", "Unavailable"];
}
}
return [true, "", "Choose"];
}
$('#datepicker').datepicker({
beforeShowDay: noFollowingMonday
});
Upvotes: 1