Reputation: 2837
I have a date picker:
<link rel="stylesheet" type="text/css" href="/css/jquery-ui-1.8.17.custom.css"/>
<script src="/js/jquery-1.7.1.min.js"></script>
<script src="/js/jquery-ui-1.8.17.min.js"></script>
<div id="pickerdiv"></div>
<script>
$(document).ready(function(){
$('#pickerdiv').datepicker({
beforeShowDay: function(date){
//some code
return [true, ''];
}
});
});
</script>
The problem is that date picker always sends in an invalid date. Today is feb 29th and the date it sends is always Jan 29th. In addition chrome's debugger says its type is "Invalid Date". I've also tried switching it from a div to an input with the same result.
Is there any way to get a valid date sent into my beforeShowDay function? Thanks.
Upvotes: 0
Views: 1148
Reputation: 69915
It does give the right date.
Here is the working example http://jsfiddle.net/ShankarSangoli/ARzrX/
Note: beforeShowDay
is called for every day it renders on the calendar starting form a month before than the current date till the last week of current month and the days of the next month in the last week if any. Because of this you are seeing Jan 29th as the first day.
I think you are looking for some other event. May be beforeShow
?
Upvotes: 1
Reputation: 30099
Seems to work fine for me: http://jsfiddle.net/y5FbY/
Watch the console output.
It should be noted that this is called as it renders each day onto the calendar, as well as some non-visible days. It starts one month prior to today (Jan 29th) and goes until the end of the current week, I think (Mar 3rd). You are simply seeing the first call of many.
That is my guess, but you may be seeing something else. It's difficult to say without a working example of your situation.
Upvotes: 2