I have a problem with beforeShowDay .
When my page loads, the days I said highlight are not highlighted until I click the day on the calendar. Also, if I press the button for the next month and return to the original month, the βselectedβ days will be highlighted as expected.
So, only at the initial draw of the calendar, the dates are not highlighted, as I programmed them. Any click on the calendar captures itself.
Am I missing the init option? See my sample code below. My test url is in a secure directory with the user / pass test / test. Look at the mini-feces at the bottom of the right column. Go to the next month and come back to see my problem. Pay attention to the marked days im May. Also, note that the βyearβ drop-down is also missing until you click.
http://www.urbanbands.com/dev/cgi-bin/links/eventmgr.cgi?do=list
The code:
<script> $(document).ready(function(){ // get the current date var today = new Date(); var m = today.getMonth(), d = today.getDate(), y = today.getFullYear(); // Need list of event dates for THIS month only from database. // Declare 'dates' var before adding "beforeShowDay" option to the datepicker, // otherwise, highlightDays() does not have the 'dates' array. dates = []; fetchEventDays(y, m+1); $('#datepicker').datepicker({ dateFormat: 'yy-mm-dd', changeMonth: true, changeYear: true, setDate: today, inline: false }); $('#datepicker').datepicker('option', 'onChangeMonthYear', fetchEventDays); $('#datepicker').datepicker('option', 'beforeShowDay', highlightDays); $('#datepicker').datepicker('option', 'onSelect', getday); // ------------------------------------------------------------------ // getday // ------------------------------------------------------------------ function getday(dateText, inst) { $('#content').load('http://www.mydomain/eventmgr.cgi?do=view_day;date='+dateText+' #eventMgr_content', function() { alert('Load was performed. '+dateText); }); } // ------------------------------------------------------------------ // fetchEventDays // ------------------------------------------------------------------ function fetchEventDays(year, month) { var paramStr ='?do=get_event_dates&yr=' + year + '&mo=' + month; $.get('<%config.db_cgi_url%>/eventmgr-ajax.cgi'+ paramStr, function(data) { var recur_dates = data.split(','); for(var i = 0; i < recur_dates.length; i++) { var date_parts = recur_dates[i].split('-'); dates.push(new Date(date_parts[0], date_parts[1]-1, date_parts[2])); } // This causes dates with events to highlight on initial draw, but // when clicking to the next month, it switches back to orig month. // $('#datepicker').datepicker('option', {}); // Refresh }); } // ------------------------------------------------------------------ // highlightDays // ------------------------------------------------------------------ function highlightDays(date) { for (var i = 0; i < dates.length; i++) { if ((dates[i].getTime() == date.getTime())) { return [true, 'highlight']; } } return [true, '']; } }); </script>