In jQuery datepicker beforeShowDay if fails
- by michalzuber
HI. I'm having problem to highlight more days. Somehow the if statement in beforeShowDay isn't true when it should be :(
dateString typeof is string and an example is available in the screenshot at http://mikaelz.host.sk/datepicker.png
Pasted code:
var dates = new Array();
function addDate(date) {if (jQuery.inArray(date, dates) < 0) dates.push(date);}
function removeDate(index) {dates.splice(index, 1);}
function addOrRemoveDate(date) {
var index = jQuery.inArray(date, dates);
if (index >= 0)
removeDate(index);
else
addDate(date);
}
function padNumber(number) {
var ret = new String(number);
if (ret.length == 1)
ret = "0" + ret;
return ret;
}
jQuery(document).ready(function(){
jQuery("#pick-date").datepicker({
onSelect: function(dateText, inst) { addOrRemoveDate(dateText); },
beforeShowDay: function (date){
var year = date.getFullYear();
var month = padNumber(date.getMonth());
var day = padNumber(date.getDate());
var dateString = day + "." + month + "." + year;
if (dates.indexOf(dateString) >= 0) {
return [true,"ui-state-highlight"];
}
return [true, ""];
}
});
});
Big thanks for any good ideas what could be wrong.