flatpickr / flatpickr

lightweight, powerful javascript datetimepicker with no dependencies
https://flatpickr.js.org
MIT License
16.12k stars 1.45k forks source link

With allowInput=true, changes on time input are lost when clicking outside #2957

Open EmilieLethu opened 10 months ago

EmilieLethu commented 10 months ago

https://jsfiddle.net/gveqz7Ld/

Your Environment

Current behavior

  1. Click on time input field
  2. Change time by typing or scrolling
  3. Click outside input field
  4. Changes are lost

Example below : first with scrolling, second with typing

example.webm

Expected behavior

  1. Click on time input field
  2. Change time by typing or scrolling
  3. Click outside input field
  4. Time is updated (the same way it would have been if you had press Tab or Enter instead of clicking outside)
noahfpf commented 6 months ago

It looks like this bug is caused by https://github.com/flatpickr/flatpickr/blob/master/src/index.ts#L1480, which sets the value from the input value when a document click occurs and the time UI has lost focus if self.config.allowInput is true. That call overwrites the value typed into the time UI.

Code causing this bug:

function documentClick(e: MouseEvent) {
  [...]

  if (lostFocus && isIgnored) {
    if (self.config.allowInput) {
      self.setDate(
        [...]

I don't see any easy work-around, but would be happy to hear if anyone else has a solution.