I've gone through literally every post on this topic. It's not something new. Yet every time some one comes here with the same problem in different context. Seems like JQUERY UI should support this inherently in its next big release. Ok, now here is my code, where I want to enable only those dates in datepicker returned from a controller to my view, which I input in <input> hidden fields. Here is my html:
<?php foreach ($trip_dates as $single_trip_date) { ?>
<form id="datesetter">
<?php $date = new DateTime($single_trip_date->trip_date); ?>
<input type="hidden" value="<?= $date->format('d-m-Y'); ?>"/>
and this is my code:
$(document).ready(function(){
var date_d = [];
$("#datesetter input[type=hidden]").each(function() {
var date_d = new Date();
date_d = [$(this).val()];
console.log(date_d); // Output is: ["12-01-2016"] ["14-01-2016"]
function addZ(n) {
return (n < 10? '0' : '') + n;
}
function available(date) {
dmy = addZ(date.getDate()) + "-" + addZ((date.getMonth()+1)) + "-" + date.getFullYear();
if ($.inArray(dmy, date_d) == -1) {
console.log(dmy);
console.log("php dates: "+date_d); //out put is only first date in series, i.e. 12-01-2016
return [false, ""];
} else {
return [true,"","Unavailable"];
}
}
$('#datepick').datepicker({
dateFormat: 'dd/mm//yy',
beforeShowDay: available
});
});
});
But when I see output in console.log for available dates in available function, it prints series of first date only repeatedly, there is no sign of another date, which is 14-01-2016.
In result, only 12th date is enabled in datepicker, but all else disabled. I want all the dates in date_d variable to be enabled. can anybody tell me how to do it?