I'm trying to make something work - I get the message "Uncaught TypeError: cannot read property" 0 "from undefined" with the following, and I can’t understand why!
I am trying to use the jQuery UI datepicker on a holiday cottage site to indicate availability and season (low, high, etc.). I have a function as a datePicker event to check if there is a reservation for a date, and if not, then I go out to check what season we are in. (Off-peak seasonal orders can be done on Monday or Friday. At peak season, this is only on Fridays.)
I use cms to create some arrays of dates (through loops) that can then be executed when creating a calendar, so javascript is a bit detailed.
Arrays are as follows:
<script>
var ps1 = new Date('June 17, 2011');
var pe1 = new Date('September 2, 2011');
var ps2 = new Date('December 19, 2011');
var pe2 = new Date('January 6, 2012');
var peakStart = new Array(ps1,ps2);
var peakEnd = new Array(pe1,pe2);
var cbs1 = new Date('May 27, 2011');
var cbe1 = new Date('June 5, 2011');
var cbs2 = new Date('September 1, 2011');
var cbe2 = new Date('September 18, 2011');
var cottageStart = new Array(cbs1,cbs2);
var cottageEnd = new Array(cbe1,cbe2);
var lastDate = '01/06/2012';
</script>
I have the following function that I call from the beforeShowDate event to check the calendar date on the reservation array:
$('#cottageCal').datepicker({
minDate: '0d',
maxDate: lastDate,
beforeShowDay: function(date) {
$.each(cottageStart, function(key, value) {
if ((date >= value) && (date <= value)) {
return [false, 'booked'];
} else {
return checkPeak(date);
}
});
}
});
Finally, the checkPeak function called from here looks like this:
var checkPeak = function(date) {
var day = date.getDay();
var month = date.getMonth();
$.each(peakStart, function(key, value) {
if ((date > value) && (date < value)) {
if (month != 11) {
return [(day == 5), ''];
} else {
return [(day == 1), ''];
}
}
if (month == 0) {
return false;
} else {
return [(day == 1 || day == 5), ''];
}
});
}
I have to do something fundamentally wrong, but I don’t see that!