fix: fire onChange when a typed value is committed by clicking outside by kira0269 · Pull Request #3136 · flatpickr/flatpickr · GitHub
Skip to content

fix: fire onChange when a typed value is committed by clicking outside - #3136

Open
kira0269 wants to merge 1 commit into
flatpickr:masterfrom
kira0269:fix-2941-announce-typed-value-on-outside-click
Open

kira0269 wants to merge 1 commit into
flatpickr:masterfrom
kira0269:fix-2941-announce-typed-value-on-outside-click

Conversation

@kira0269

Copy link
Copy Markdown

With allowInput, documentClick commits what the user typed by calling
setDate with triggerChange=false, so the value silently changes: no
onChange hook, no change/input event on the input, no onValueUpdate.
Anything bound to the field (a framework model, a form listener) never
learns the date moved. Pressing Enter or leaving with Tab do announce
the same edit, so the field is only silent for the most common gesture.

onBlur cannot cover the case on its own. Clicking a non-focusable
element commits the value without ever blurring the input, and when a
blur does follow, documentClick has already applied the value, leaving
onBlur's valueChanged guard nothing to detect.

Trigger the change from documentClick under the same guard onBlur uses,
so a commit that moved the value is announced exactly once and a
dismissal that changed nothing stays silent.

Fixes #2941

  With allowInput, documentClick commits what the user typed by calling
  setDate with triggerChange=false, so the value silently changes: no
  onChange hook, no change/input event on the input, no onValueUpdate.
  Anything bound to the field (a framework model, a form listener) never
  learns the date moved. Pressing Enter or leaving with Tab do announce
  the same edit, so the field is only silent for the most common gesture.

  onBlur cannot cover the case on its own. Clicking a non-focusable
  element commits the value without ever blurring the input, and when a
  blur does follow, documentClick has already applied the value, leaving
  onBlur's `valueChanged` guard nothing to detect.

  Trigger the change from documentClick under the same guard onBlur uses,
  so a commit that moved the value is announced exactly once and a
  dismissal that changed nothing stays silent.

  Fixes flatpickr#2941

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using altInput and allowInput: 'change' event for hidden input is not always detectable

1 participant