I am using jquery ui for datepicker and I am trying to disable some dates. I have searched that we can achieve this via beforeShowDay on datepicker initialisation. However I cant seem to make it work with the following code:
$(function(){
$('.my-datepicker').datepicker({
beforeShowDay: function(d){
return [ false, "test-class", "Not available" ];
}
});
}());
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<input type="text" class="form-control my-datepicker" name="StartDate" id="StartDate">
I am able to make it work in the snippet above but I really cannot understand why in my actual app the datepicker shows but all dates are still selectable.
When I add a breakpoint on the beforeShowDay return the code does enter that function but still all days are selectable.
I am running out of ideas so perhaps somebody have encountered a similar problem and can give some ideas where to look.
$(document).on('click', '.addEvent', function(){
var params = {
'SWFCustomerLocationID': $(this).data('swfcustlocid')
}
// Load the SWFCustomerDetails Modal
$.get(base_url + '/settings/components/createPickupOrDeliverySchedule.php', params, function(response){
$(document).find("#createPickupOrDeliveryScheduleForm").remove();
$(document).find('body').append(response.html);
$("#createPickupOrDeliveryScheduleForm").modal('show');
initializeInstrumentAccordion();
$('.chosen-select').chosen({width: '100%'});
var startDate = Date.parse(response.StartDate);
var endDate = Date.parse(response.EndDate);
$('#StartDate').datepicker({
startDate: new Date(startDate),
endDate: new Date(endDate),
dateFormat: 'yyyy-mm-dd',
// beforeShowDay: function(d){
// var day = d.getDate();
// if (day < 10) {
// day = "0" + day;
// }
// var month = d.getMonth() + 1;
// if (month < 10) {
// month = "0" + month;
// }
// var year = d.getFullYear();
// var dString = `${year}-${month}-${day}`;
// var result = [ false, "", "Not available" ];
// return result;
// }
beforeShowDay: function(d){
return [false, "", "Not available"];
}
});
});
})
