ciao @wistvan,
the trick is in the line with ‘return date.getDay() == 2’… in the first example I used date.getDay() that returns the number of the day of the week (Wednesday was the number 2).
But we could also compare the date instead, so we can use Date with .getTime() that returns the day in epoch (in addition to correctly compare the date we need to get this midnight date -> new Date().setHours(0, 0, 0, 0))
– before the script can we need to create an array of days to exclude and then we would use indexof to verify that the day passed by beforeShowDay is not one of the excluded days
– you could exclude all days before today simply comparing thisDay > date.getTime() or vice versa
This is the script the snippet you need to add to your js file or by injecting that code into the form in this way
window.addEventListener('load', function(){
jQuery(function($){
var thisDay = new Date().setHours(0, 0, 0, 0);
var excludedDays = [
thisDay,
thisDay - 864e5 , // yesterday 864e5 == 86400000 == 24*60*60*1000
thisDay - 864e5 * 15, // two weeks ago
thisDay + 864e5 * 3 // in three days
];
$("#datepicker").click(function(e){
e.preventDefault();
}).datepicker({
dateFormat: "yy-mm-dd",
beforeShowDay: function (date) {
console.log(date.getTime());
return excludedDays.indexOf(date.getTime()) > -1 ? [false, " disabled"] : [true, " enabled"];
}
});
});
});
-
This reply was modified 2 years, 10 months ago by Erik. Reason: fix