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

rangeIncomplete event fires when a date is set in the anchor input after first being set on the follower input #95

Closed jkallay1 closed 7 years ago

jkallay1 commented 7 years ago

If the anchor is the start input: When a value is set in the start input for the first time, in line 267 of datepair.js the newTime variable is successfully initialized but this.timeDelta is null, and won't be set to a non-null value. Thus when _validateRanges is called the null test of this.timeDelta will cause the rangeIncomplete event to fire. I think the fix is to set a non-null value to this.timeDelta before initializing newTime.

jonthornton commented 7 years ago

This only happens when defaultTimeDelta is set to null. The point of defaultTimeDelta is to solve exactly this problem, and it defaults to 1 hour. Please provide a code sample if you're still experiencing problems.

jkallay1 commented 7 years ago

Sorry, I completely botched the original bug description. I had to reread it myself about a dozen times to figure out what I had been talking about. As you noted, the issue occurs when defaultTimeDelta is null. But the information I left out is that the follower (non-anchor) input has a time set on it first. The rangeIncomplete event fires. Then, when a time is set on the anchor, the rangeIncomplete anchor fires again (even though the range isn't incomplete). See this jsFiddle: https://jsfiddle.net/ez7khL74/