I try to use datepicker to show a busy/free calendar. I use beforeShowDay to switch between two classes, but it doesn't work. The last day apply the class for all dates.
var SelectedDates = {};
SelectedDates['2014-05-04'] = true;
SelectedDates['2014-05-03'] = true;
SelectedDates['2014-05-02'] = true;
$(function() {
$("#datepicker").datepicker({
numberOfMonths: 3,
showCurrentAtPos: 1,
beforeShowDay: function (date) {
var dateFormatted = date.getFullYear() +
"-" + (date.getMonth() < 10 ? "0" + date.getMonth() : date.getMonth()) +
"-" + (date.getDate() < 10 ? "0" + date.getDate() : date.getDate());
console.log("date js: " + dateFormatted + " highlight: " + SelectedDates[dateFormatted]);
var highlight = SelectedDates[dateFormatted];
if (highlight === true) {
console.log("add busy class to " + dateFormatted);
return [false, 'Busy'];
}
console.log("add free class to " + dateFormatted);
return [true, 'Free'];
}
});
});
Here's the fiddle : http://jsfiddle.net/b22Bz/
Thanks,