uxsolutions / bootstrap-datepicker

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

Trying to programmatically set range to 6 days after first chosen date #2636

Open anthonybenjamin opened 3 years ago

anthonybenjamin commented 3 years ago

Attempting to programmatically set range to 6 days after the first chosen date.

Example:

User clicks on a Monday in the first range input box and the rage automatically updates in UI as well as in backend to be that Sunday.

What happens instead:

Either, I get one input box to update (the first one) only to see the second box to match it, or the last one simply does not update at all.

Datepicker version used

1.9.0

https://jsfiddle.net/abenaminupwork/2gw41qsk/3/

phanos commented 3 years ago

I looked at your code, this works for setting the second date, based on the first:

    $('.first').on('change', function(){
      let d = new Date($('.first').datepicker('getDate'));
      d.setDate(d.getDate() + 6);
      $('.second').datepicker('setDate', d);
    })