I am using the jquery ui datepicker in my app. I have created an inline datepicker. I am having a problem with onChangeMonthYear. I have simplified the example to bare minimum.
Onclick of "prev" or "next", the calendar should: -
The problem is with #2.
I am using setDate to do that, and it is ending up in infinite recursion. Because, I am calling setDate inside onChangeMonthYear. And setDate is also firing onChangeMonthYear internally.
How can I achieve those 3 things when prev/next is clicked.
inside the jQuery script code just paste the code. $( ". selector" ). datepicker({ dateFormat: 'yy-mm-dd' });
If you like to restrict access of users to select a date within a range then there is minDate and maxDate options are available in jQuery UI. Using this you can set the date range of the Datepicker. After defining these options the other days will be disabled which are not in a defined range.
$(". selector"). datepicker( {defaultDate:"+6"} );
Try setting a flag that you can query in your event handler to prevent the infinite loop:
var changingDate = false;
$('.selector').datepicker({
onChangeMonthYear: function(year, month, inst) {
if (changingDate) {
return;
}
changingDate = true;
// your setDate() call here
changingDate = false;
}
});
The infinite recursion means you are informing the incorrect month.
Make sure you are decreasing 1 from month
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