Tengo un problema con beforeShowDay
.jQuery Datepicker beforeShowDay funciona solo después del primer clic
Cuando se carga mi página, los días que he indicado destacar no se resaltan hasta que hago clic en un día en el calendario. Además, si hago clic en el botón del mes siguiente y vuelvo al mes original, los días 'seleccionados' se resaltan como se espera.
Por lo tanto, solo en el sorteo inicial del calendario las fechas no se resaltan como las he programado. Cualquier clic en el calendario se arregla solo.
¿Se echa en falta una opción init? Por favor, mira mi ejemplo de código a continuación. Mi url de prueba está en el directorio protegido con un usuario/pase de prueba/prueba. Mira el mini-cal en la parte inferior de la columna derecha. Pase al mes siguiente y vuelva para ver mi problema. Tenga en cuenta los días destacados de mayo. Además, tenga en cuenta que el menú desplegable 'año' también falta hasta que ocurre un clic.
http://www.urbanbands.com/dev/cgi-bin/links/eventmgr.cgi?do=list
El código:
<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>