Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatePicker does not dispatch change event if value is manually cleared or force cleared #950

Open
Tracked by #1621
brunnerh opened this issue Dec 28, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@brunnerh
Copy link
Contributor

This applies to datePickerType="single", probably to "range" as well. In this case the change event is fired indirectly via the onChange event of flatpickr.

Steps to reproduce:

  1. Add DatePicker with...
    1. A maxDate multiple years in the past (e.g. 20 years), this can cause a forced clear if a partial date is typed.
    2. dateFormat="Y-m-d"
  2. Add on:change listener that logs dateStr/processes date.
  3. Select a date with the calendar popup.
  4. Clear the value either...
    1. manually via the keyboard (delete everything)
    2. via a forced clear. e.g. reduce 2000-01-31 to just 200 and click/tab away. (If it only gets reduced to something like 2000-, the value gets completed, in this case to 2000-01-01. This fires a change event.)

REPL (Use With max in past for the forced clear case)

This REPL shows one of the use cases for the event: Creating a value input/change event output loop to create a component that has a Date-typed prop. value alone cannot be bound and reactively set at the same time as that would constitute a circular dependency.


Flatpickr has an event onValueUpdate that probably could be considered, as onChange does not appear to fire on clear.

@metonym
Copy link
Collaborator

metonym commented Dec 30, 2021

Related #314

  • on:change should fire when the value is manually updated and input blurred
  • consider using on:input for individual character updates per your suggestion
  • should there be an on:clear event?

@metonym metonym added the bug Something isn't working label Dec 30, 2021
@brunnerh
Copy link
Contributor Author

@metonym

  • on:change should fire when the value is manually updated and input blurred
  • consider using on:input for individual character updates per your suggestion

Not sure what suggestion you are referring to but yes, an input event should fire for individual characters while change should only be fired after the edit was made and it is considered complete (blur + value different from before).

  • should there be an on:clear event?

Could be helpful for certain use cases (e.g. revert to a better default), if you mean that this should fire if flatpickr causes the clear, but it should coincide with a change event, so not both events have to be handled to cover all changes.

I was thinking about how that could be done and played around with blur and onValueChange to detect change and clear; maybe this is helpful: REPL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants