I try to disable some dates after I have initialised the Date Picker.
I am initialising the picker like this:
$( document ).ready(function() {
$('#inputDatetime').pickadate({
format: 'dd. mmmm yyyy',
formatSubmit: 'yyyy-mm-dd',
min: dt,
selectYears: 2,
selectMonths: true
});
});
The user now performs some action that triggers an onChange()
event. The disableDates()
function prepares some more dates to disable and sets it to the picker using the set
method:
function disableDates() {
var disabledDays = [];
$.ajax({
url: 'partners/getInactiveDays',
dataType: 'json',
async: false,
success: function(data) {
$.each(data.days, function(i, d) {
disabledDays.push(parseInt(d.Day.id));
});
}
});
var $input = $('#inputDatetime').pickadate();
var picker = $input.pickadate('picker');
picker.set({
disable: disabledDays
});
}
Please note that in my case disableDays contains integers (reffering to weekdays) and dates according to the documentation (http://amsul.ca/pickadate.js/date/#disable-dates).
When the disableDates()
function is triggered for the first time, it correctly disables the dates that I retrieved with AJAX. As soon as it is triggered a second time, the picker does not seem to be updated anymore. I guess the picker has to be rendered again somehow to reflect the changes. I tried to .stop()
and .start()
and .render()
, without any effect.
How can I disable dates and refresh the picker correctly?