uxsolutions / bootstrap-datepicker

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

calling clearDates on date range picker (on document load) breaks customization #1666

Open stevevg opened 8 years ago

stevevg commented 8 years ago

I'm using v1.5.0, if I trigger a change event on a checkbox on page load, and this action triggers a clearDates on a datepicker with custom settings, all custom settings are lost.

In the following fiddle, I set

Broken (onload triggered event) https://jsfiddle.net/past12/ftxy6zhe/1/

This works (not triggered event) https://jsfiddle.net/past12/ftxy6zhe/

The code works with onload triggered event if you try to set the event to "click" instead of "change".

frederikprijck commented 8 years ago

I modified your code and it works without any problem. The main issue is the flow in which your code is exectuted:

In your fiddle, when the page loads the following is happening:

So to fix this, you have to make sure your datepickers are initialized before calling clearDates as I did here: https://jsfiddle.net/ftxy6zhe/3/ It is pretty normal that your fiddle behaves strange, how are you supposed to clear something which doesn't exist yet ?