Can't get jQueryUI datepicker option beforeShowDay
to work.
I've tried different help topics I've found but I can't get it working.
I get this error
Uncaught TypeError: Cannot read property '0' of undefined
This is my JS. but it doesn't seems to work
<script type="text/javascript">
jQuery(document).ready(function () {
var your_dates = [new Date(13, 5, 5), new Date(13, 5, 10)];
jQuery("div#event-calender").datepicker({
beforeShowDay: function (date) {
if (jQuery.inArray(date.toString(), your_dates) != -1) {
return [true, 'highlight'];
}
}
});
});
</script>
You need to always return an array, not just when a condition matches.
From the documentation:
beforeShowDay
Type: Function( Date date )
A function that takes a date as a parameter and must return an array
jQuery(document).ready(function () {
var your_dates = [new Date(13, 5, 5), new Date(13, 5, 10)];
jQuery("div#event-calender").datepicker({
beforeShowDay: function (date) {
var arr;
if (jQuery.inArray(date.toString(), your_dates) != -1) {
arr = [true, 'highlight'];
}else {
arr = [true, ''];
}
return arr;
}
});
});
FIDDLE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With