jQuery UI Datepicker:
Hi,
I'm trying to have the pop-up calendar allow only the Monday dates in the future to be selected. I've tried this code:
$(function() {
$('#dateWeekly').datepicker({
showOn: 'both', // use to enable calendar button and focus
开发者_开发百科 buttonImage: 'childtime/images/calendar.gif',
buttonImageOnly: true,
buttonText: 'Show Calendar',
numberOfMonths: 3,
showButtonPanel: true,
minDate: -0, maxDate: '+12M',
// beforeShowDay: function(date){ return [date.getDay() == 1,""]}
beforeShowDay: function(date) { return [date.getDay() == 1, "" && date.getTime() != today.getTime(), ""]; }
});
});
This disables all past dates, and disables all future days except Mondays (so far so good), but it fails to disable today's date if today is Monday. Any suggestions will be appreciated. Thanks!
Set minDate
to +1d
.
As you are supposed to pick only future mondays, today shouldn't be able to be picked, no matter what day it is.
And you can simplify your beforeShowDay to:
beforeShowDay: function(date) {
return [date.getDay() == 1, ""];
}
Below Code might be the solution for this question.
beforeShowDay: function(date) {
returnFlag = true;
currentDate = new Date();
if( date.getDay() == 1 && date.getDate() == currentDate.getDate()
&& date.getMonth() == currentDate.getMonth()){
returnFlag = false;
}
return [returnFlag,'',false];
}
Maybe that could help
$(function() {
$('#dateWeekly').datepicker({
showOn: 'both', // use to enable calendar button and focus
buttonImage: 'childtime/images/calendar.gif',
buttonImageOnly: true,
buttonText: 'Show Calendar',
numberOfMonths: 3,
showButtonPanel: true,
minDate: -0, maxDate: '+12M',
beforeShowDay: function(date) {
// from here
var selectable = true;
var today = new Date()
if( today.getDay() == 1 && date.getDate() == today.getDate() )selectable = false;
return [selectable,'',false];
// til here
}
});
});
精彩评论