jonthornton / Datepair.js

A javascript plugin for intelligently selecting date and time ranges, inspired by Google Calendar.
https://www.jonthornton.com/Datepair.js
358 stars 87 forks source link

possible refresh bug? #64

Closed KrunchMuffin closed 8 years ago

KrunchMuffin commented 8 years ago

I don't know if you will consider this a bug or not, but in this example http://jsfiddle.net/fv9m5my0/21/

go ahead and put in say 5am, the end time will go to 6am as expected, then change start to 5pm, the end time won't change. Now if you take out the refresh it does work. I don't have this exact setup, but I do have the refresh down the line. Don't know if I need it, but I put it there for a reason at the time.

jonthornton commented 8 years ago

The refresh method should only be used if you're modifying an input value in a way that doesn't trigger a change event - like $('#someTimeInput').val(someNewTime). If you don't think you need to call refresh, you probably don't.

I don't think it's a bug. My guess is that the startTime changeTime handler is being called before the startTime change event gets handled by Datepair. The refresh call in the changeTime handler makes Datepair update its interval state. When the change event does get handled by Datepair, it thinks nothing has changed because its internal state matches the values in the inputs.