In my situation:
I got the days which want to be enabled from ajax called. When I change the month ,I read the xml file vial ajax called and got the days of that month.H
The problem is the date format here, when you're storing the dates they're coming out as 2010-1001
instead of 2010-10-01
, so change this:
$daysWithRecords.push(dateToFind+$(this).text());
To this:
$daysWithRecords.push(dateToFind+"-"+$(this).text());
You can see it working here.
Here's an overall more optimized version as well, less looping and no infinitely growing array:
var daysWithRecords = [];
function initDaysArray( $xml , year , month ) {
var d = year+'-'+month;
daysWithRecords =
$xml.find('user[id="126"] whDateList[month="'+d+'"] date').map(function() {
return d+"-"+$(this).text();
}).get();
}
function checkAvailability(availableDays) {
var checkdate = $.datepicker.formatDate('yy-mm-dd', availableDays);
for(var i = 0; i < daysWithRecords.length; i++) {
if(daysWithRecords[i] == checkdate){
return [true, "available"];
}
}
return [false, ""];
}
$('#div').datepicker({
dateFormat: 'yy-mm-dd',
defaultDate: '2010-09-01',
onChangeMonthYear: getDays,
beforeShowDay: checkAvailability
});
You can test it here.