In jQuery datepicker beforeShowDay if fails
Posted
by michalzuber
on Stack Overflow
See other posts from Stack Overflow
or by michalzuber
Published on 2010-05-16T07:38:37Z
Indexed on
2010/05/16
7:40 UTC
Read the original article
Hit count: 213
jquery-ui
|JavaScript
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.
© Stack Overflow or respective owner