I am using a jQuery UI Datepicker, such that only Sunday can be selected.
What I would like to happen is have it where no dates from the current date into the future can be selected. Here is the code I am using currently:
var daysToDisable = [1,2,3,4,5,6];
$('#startdate').datepicker({
beforeShowDay: disableSpecificWeekDays
});
function disableSpecificWeekDays(date) {
var day = date.getDay();
for (i = 0; i < daysToDisable.length; i++) {
if ($.inArray(day, daysToDisable) != -1) {
return [false];
}
}
return [true];
}
I would just use the single entry to restrict the date to nothing beyond today:
$('#startdate').datepicker({
maxDate: '+0d'
});
You can use the maxDate property to prevent the selection of future dates.
Note: this assumes your dateFormat is dd/mm/yy
Edit: http://jsfiddle.net/jXGZz/
var fullDate = new Date();
var twoDigitMonth = ((fullDate.getMonth().length+1) === 1)? (fullDate.getMonth()+1) : '0' + (fullDate.getMonth()+1);
$('#startdate').datepicker({
maxDate: fullDate.getDate() + "/" + twoDigitMonth + "/" + fullDate.getFullYear(),
beforeShowDay: disableSpecificWeekDays
});
function disableSpecificWeekDays(date) {
if(date.getDay()==0){
return [true];
}else{
return [false];
}
}
Modified twoDigitMonth
var twoDigitMonth = fullDate.getMonth()+1<10 ? "0"+fullDate.getMonth()+1 : fullDate.getMonth()+1 ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With