Closed softail closed 10 months ago
How about using datesDisabled
with callback function, like this?
var datepicker = new Datepicker(elem, {
datesDisabled(date, viewId) {
if (viewId > 0) {
return;
}
const dt = new Date();
const maxDateVal = dt.setDate(dt.getDate() + 14);
return date.getTime() > maxDateVal;
},
});
https://codepen.io/mymth/pen/wvYZzqe
If you use v1.2 or earlier, using beforeShowDay
would work similar, but it only prevents users from clicking the date—users can enter the date by typing it into the input field. So, there's no true solution in this case, unfortunately.
I use an array of dates for datesDisabled
, but beforeShowDay
function did the job thanks!
Just in case you aren't aware of this, disabling dates (or months/years/decades) with the beforeShow*** hook is deprecated and will be removed. Therefore, unless you plan to never update this library, your code will stop working at some point in the future.
If you need to disable some specific dates too, I highly recommend doing like this.
const datesToDisable = [ /* ...some dates */ ];
var datepicker = new Datepicker(elem, {
datesDisabled(date, viewId) {
if (viewId > 0) {
return;
}
if (datesToDisable.find(toDisable => date.toDateString() === toDisable.toDateString())) {
return true;
}
const dt = new Date();
const maxDateVal = dt.setDate(dt.getDate() + 14);
return date.getTime() > maxDateVal;
},
});
(I updated the example https://codepen.io/mymth/pen/wvYZzqe)
Just FYI.
PS. It would be appreciated if you close the issue if your problem is solved.
Hey, I've looked around docs and issues, but could not find the answer. I have an odd requirement to still show the future months to users, even though maxDate is used.
For example on this screen below i have set maxDate to 1st of June and I want to still click on nextButton, is this possible?