Here I have a hacking solution that works for me to change the datepicker options dynamically after I initiate a bootstrap datepicker object.
var id = "MyDatepicker"
var beginDate = new Date();
var endDate = new Date(2022, 11, 17, 3, 24, 0);
function myCallBack(date) {
if ((beginDate <= date) && (date <= endDate)){
return {classes: 'activeClass'};
}
return;
}
$('#' + id ).datepicker({
startDate: new Date(),
language: 'en'
});
$('#' + id ).datepicker('_process_options', {
beforeShowDay: function(date) {
return myCallBack(date);
}
}).datepicker('update','')
In this case. I apply a class to a range of dates on the datepicker.
I use the "non public" datepicker method '_process_options' to change intern datepicker methods.
With this method I can change all the options of the datepicker instance because the '_process_options' has no method validator.
Also I use the method 'update' bacause the dobbleclick bug: bootstrap datepicker, beforeShowDay works after second click