Datepicker flips back to initial date
I'm highlighting dates on an inline Datepicker. It works like this:
1) user changes month or year in Datepicker
2) onChangeMonthYear fires calling my custom Function that has a JSON call to get the dates I need
3) JSON is returned in the Function and has a callback that contains beforeShowDay
4) Dates are compared in beforeShowDay and the Datepicker css is adjusted accordingly for each date.
This works, except I have a problem where the Datepicker is automatically flipping back to todays month/year.
For example, we're in Aug. 2010. The user moves ahead to Sept. 2010 and the Datepicker flips back to Aug. 2010 after the JSON callback containing beforeShowDay is called. Here's my code for that:
Any ideas? Thanks
- function dpGetAppts(y, m, id, p) {
- $.getJSON('_URL_?y=' + y + '&m=' + m + '&id=' + id + '&p=' + p, function (j) {
- $('.global_cal').datepicker('change', {
- beforeShowDay: function (date) {
- for (i = 0; i < j.length; i++) {
- if (date.getMonth() == j[i][0] - 1
- && date.getDate() == j[i][1]
- && date.getFullYear() == j[i][2]) {
- return [true, "_CSS_CLASS_"];
- }
- }
- return [true, ""];
- }
- });
- // ONCE EXECUTION GETS TO HERE, DATEPICKER FLIPS BACK TO TODAY'S DATE
- });
- }