lundi 2 février 2015

Dynamic datepicker disappearing

I have a PHP function that gets dates from a database that need to be highlighted and disabled on the date picker.


I have a function that works if I declare the dates like var disabledDates = ["12-02-2015"]; but when I try using var disabledDates = <?php echo json_encode($date); ?>; the date picker disappeared from the screen. Is there a reason why this is happening?


Below is my code:



<script>
function unavailable(date) {
var dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear(); console.log(dmy);
var disabledDates = <?php echo json_encode($date); ?>;

if ($.inArray(dmy, disabledDates) < 0) {
return [true,"",""];
} else {
//the second parameter you can set your css class
return [false,"red","Day unavailable"];
}
}

$('#datepicker').datepicker({
altField : '#hiddenFieldID',
format: 'dd-mm-yyyy',
changeMonth:true,
minDate: 14,
beforeShowDay: unavailable //here it is
});
</script>


PHP:



$fullybooked = getfullybookeddays();
$dates = array();
$i = '0';

while($row = mysql_fetch_assoc($fullybooked)){

$dates[$i] = str_replace('/', '-', $row['hdate']);
$i++;

}

$date_list = '["' . implode('", "', $dates) . '"]';

Aucun commentaire:

Enregistrer un commentaire