Disable date if once selected jquery.ui.datepicker
I have 10 jquery.ui.datepicker in my website. If somebody selects todays date in first datepicker, want to disable todays date in second datepicker. So like in 3rd, fourth and sixth etc etc. Means if one date selected in any datepicker that could not be selectable in other datepickers.
For time being I done like this... but its working from top to bottom...means datepicker 1 to 10.... its not working from datepicker 10 to 1.... means if select today in datepicker10, can select same date datepicker9 also ... So i want to disable that one also...disable selected date in descending and ascending order....
$(function () {
$("#datepicker1, #datepicker2, #datepicker3, #datepicker4, #datepicker5, #datepicker6, #datepicker7, #datepicker8, #datepicker9, #datepicker10").datepicker({
minDate: '+1D',
maxDate: "+90D",
showOn: "button",
buttonImage: "images/calendar.gif",
buttonImageOnly: true,
dateFormat: "D, dd M, yy",
onSelect: function (selectedDate) {
if (this.id == 'datepicker1') {
var dateMin = $('#datepicker1').datepicker("getDate");
var rMin = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 1);
var rMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 91);
$('#datepicker2').datepicker("option", "minDate", rMin);
$('#datepicker2').datepicker("option", "maxDate", rMax);
$('#datepicker3').datepicker("option", "minDate", rMin);
$('#datepicker3').datepicker("option", "maxDate", rMax);
$('#datepicker4').datepicker("option", "minDate", rMin);
$('#datepicker4').datepicker("option", "maxDate", rMax);
$('#datepicker5').datepicker("option", "minDate", rMin);
$('#datepicker5').datepicker("option", "maxDate", rMax);
$('#datepicker6').datepicker("option", "minDate", rMin);
$('#datepicker6').datepicker("option", "maxDate", rMax);
$('#datepicker7').datepicker("option", "minDate", rMin);
$('#datepicker7').datepicker("option", "maxDate", rMax);
$('#datepicker8').datepicker("option", "minDate", rMin);
$('#datepicker8').datepicker("option", "maxDate", rMax);
$('#datepicker9').datepicker("option", "minDate", rMin);
$('#datepicker9').datepicker("option", "maxDate", rMax);
$('#datepicker10').datepicker("option", "minDate", rMin);
$('#datepicker10').datepicker("option", "maxDate", rMax);
}
if (this.id == 'datepicker2') {
var dateMin = $('#datepicker2').datepicker("getDate");
var rMin = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 1);
var rMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 91);
$('#datepicker3').datepicker("option", "minDate", rMin);
$('#datepicker3').datepicker("option", "maxDate", rMax);
$('#datepicker4').datepicker("option", "minDate", rMin);
$('#datepicker4').datepicker("option", "maxDate", rMax);
$('#datepicker5').datepicker("option", "minDate", rMin);
$('#datepicker5').datepicker("option", "maxDate", rMax);
$('#datepicker6').datepicker("option", "minDate", rMin);
$('#datepicker6').datepicker("option", "maxDate", rMax);
$('#datepicker7').datepicker("option", "minDate", rMin);
$('#datepicker7').datepicker("option", "maxDate", rMax);
$('#datepicker8').datepicker("option", "minDate", rMin);
$('#datepicker8').datepicker("option", "maxDate", rMax);
$('#datepicker9').datepicker("option", "minDate", rMin);
$('#datepicker9').datepicker("option", "maxDate", rMax);
$('#datepicker10').datepicker("option", "minDate", rMin);
$('#datepicker10').datepicker("option", "maxDate", rMax);
}
if (this.id == 'datepicker3') {
var dateMin = $('#datepicker3').datepicker("getDate");
var rMin = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 1);
var rMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 91);
$('#datepicker4').datepicker("option", "minDate", rMin);
$('#datepicker4').datepicker("option", "maxDate", rMax);
$('#datepicker5').datepicker("option", "minDate", rMin);
$('#datepicker5').datepicker("option", "maxDate", rMax);
$('#datepicker6').datepicker("option", "minDate", rMin);
$('#datepicker6').datepicker("option", "maxDate", rMax);
$('#datepicker7').datepicker("option", "minDate", rMin);
$('#datepicker7').datepicker("option", "maxDate", rMax);
$('#datepicker8').datepicker("option", "minDate", rMin);
$('#datepicker8').datepicker("option", "maxDate", rMax);
$('#datepicker9').datepicker("option", "minDate", rMin);
$('#datepicker9').datepicker("option", "maxDate", rMax);
$('#datepicker10').datepicker("option", "minDate", rMin);
$('#datepicker10').datepicker("option", "maxDate", rMax);
}
if (this.id == 'datepicker4') {
var dateMin = $('#datepicker4').datepicker("getDate");
var rMin = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 1);
var rMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 91);
$('#datepicker5').datepicker("option", "minDate", rMin);
$('#datepicker5').datepicker("option", "maxDate", rMax);
$('#datepicker6').datepicker("option", "minDate", rMin);
$('#datepicker6').datepicker("option", "maxDate", rMax);
$('#datepicker7').datepicker("option", "minDate", rMin);
$('#datepicker7').datepicker("option", "maxDate", rMax);
$('#datepicker8').datepicker("option", "minDate", rMin);
$('#datepicker8').datepicker("option", "maxDate", rMax);
$('#datepicker9').datepicker("option", "minDate", rMin);
$('#datepicker9').datepicker("option", "maxDate", rMax);
$('#datepicker10').datepicker("option", "minDate", rMin);
$('#datepicker10').datepicker("option", "maxDate", rMax);
}
if (this.id == 'datepicker5') {
var dateMin = $('#datepicker5').datepicker("getDate");
var rMin = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 1);
var rMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 91);
$('#datepicker6').datepicker("option", "minDate", rMin);
$('#datepicker6').datepicker("option", "maxDate", rMax);
$('#datepicker7').datepicker("option", "minDate", rMin);
$('#datepicker7').datepicker("option", "maxDate", rMax);
$('#datepicker8').datepicker("option", "minDate", rMin);
$('#datepicker8').datepicker("option", "maxDate", rMax);
$('#datepicker9').datepicker("option", "minDate", rMin);
$('#datepicker9').datepicker("option", "maxDate", rMax);
$('#datepicker10').datepicker("option", "minDate", rMin);
$开发者_如何学Python('#datepicker10').datepicker("option", "maxDate", rMax);
}
if (this.id == 'datepicker6') {
var dateMin = $('#datepicker6').datepicker("getDate");
var rMin = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 1);
var rMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 91);
$('#datepicker7').datepicker("option", "minDate", rMin);
$('#datepicker7').datepicker("option", "maxDate", rMax);
$('#datepicker8').datepicker("option", "minDate", rMin);
$('#datepicker8').datepicker("option", "maxDate", rMax);
$('#datepicker9').datepicker("option", "minDate", rMin);
$('#datepicker9').datepicker("option", "maxDate", rMax);
$('#datepicker10').datepicker("option", "minDate", rMin);
$('#datepicker10').datepicker("option", "maxDate", rMax);
}
if (this.id == 'datepicker7') {
var dateMin = $('#datepicker7').datepicker("getDate");
var rMin = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 1);
var rMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 91);
$('#datepicker8').datepicker("option", "minDate", rMin);
$('#datepicker8').datepicker("option", "maxDate", rMax);
$('#datepicker9').datepicker("option", "minDate", rMin);
$('#datepicker9').datepicker("option", "maxDate", rMax);
$('#datepicker10').datepicker("option", "minDate", rMin);
$('#datepicker10').datepicker("option", "maxDate", rMax);
}
if (this.id == 'datepicker8') {
var dateMin = $('#datepicker8').datepicker("getDate");
var rMin = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 1);
var rMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 91);
$('#datepicker9').datepicker("option", "minDate", rMin);
$('#datepicker9').datepicker("option", "maxDate", rMax);
$('#datepicker10').datepicker("option", "minDate", rMin);
$('#datepicker10').datepicker("option", "maxDate", rMax);
}
if (this.id == 'datepicker9') {
var dateMin = $('#datepicker9').datepicker("getDate");
var rMin = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 1);
var rMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 91);
$('#datepicker10').datepicker("option", "minDate", rMin);
$('#datepicker10').datepicker("option", "maxDate", rMax);
}
}
});
});
Not tested but you should be able to do
.select(function() {
var dateMin = $(this)("getDate");
var rMin = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 1);
var rMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 91);
$('.datepicker').not(this).each(function() {
$(this).datepicker("option", "minDate", rMin);
$(this).datepicker("option", "maxDate", rMax);
});
});
精彩评论