uxsolutions / bootstrap-datepicker

A datepicker for twitter bootstrap (@twbs)
Apache License 2.0
12.66k stars 6.07k forks source link

Calendar doesn't automatically update the disabled date #975

Open sasipaants opened 10 years ago

sasipaants commented 10 years ago

I have 2 datepickeres - start date and end date. Start date picker allows user to pick any date until today. End date picker allows user to pick any date from selected start date till today. When I select start date in the previous month, the end date doesn't auto update and increase the enable dates. This works fine if the selected start date is within the same month.

timobleeker commented 10 years ago

Hi @sasilukr. I think I had a similar problem. I fixed my problem and hope the same solution can be applied to your problem if you haven't found any solution yet. I assume you're using the example on eyecon.ro as reference point. If we look at the example on with checkin and checkout dates we see this if-statement:

if (ev.date.valueOf() > checkout.date.valueOf()) { var newDate = new Date(ev.date) newDate.setDate(newDate.getDate() + 1); checkout.setValue(newDate); }

This statement sets the checkout date (and with it, the enabled and disabled dates) only when the selected checkin date is after the currently selected checkout date. I've added an else condition in here to assign the checkout date to itself in case the new checkin date is before the checkout date (edited a bit after initial post to clean up):

if (ev.date.valueOf() > checkout.date.valueOf()) { var newDate = new Date(ev.date) newDate.setDate(newDate.getDate() + 1); checkout.setValue(newDate) } else { checkout.setValue(checkout.date) } ;

Hope it helps you or other that find this issue.