Reputation: 20686
I have a strange issue with the jQuery UI datepicker. This is the questionable code:
$('#cal').datepicker();
d = new Date('07/05/2013');
$('#cal').datepicker('option','minDate',d);
d.setDate(10);
$('#cal').datepicker('setDate',d);
This should set the min date to July 5 and the selected date to July 10. However, both the min date and the selected date are being set to July 10. Why is this? jsbin demo
Note: I know I can get around this by creating two date objects, but I want to understand why this happens.
Upvotes: 0
Views: 2140
Reputation: 15975
You're updating the same object 'd'. So you're setting both dates to the same object which is set to 10.
You should instead do something like:
$('#cal').datepicker('option','minDate', new Date('07/05/2013'));
$('#cal').datepicker('setDate', new Date('07/10/2013'));
Upvotes: 2