-
Notifications
You must be signed in to change notification settings - Fork 5
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
Ds 447 build ds date field component input not updating correctly during on change validation #547
Conversation
b42fcca
to
9770fd1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly I am not 💯 to go this way because it looks hacky, but I am ok if you tested it properly if that works.
So, on the one hand - if it solves the problem, its' better than now. On the other hand it's hacky 🙂
Maybe we can merge it now and do more research + refactor working on isDirty issue.
Maybe it's more than small changes here, maybe complex refactor from scratch, dunno
9770fd1
to
3639f43
Compare
I updated the solution for this (latest commit - the rest is a rebase). It's now both less hacky and fixes the issue with |
…ld when used within a Form
3639f43
to
87aa1ec
Compare
…dler would rather than onStateChange
Edit: There was an additional problem with this field not updating in Forms correctly which Michal brought up (JIRA 2 link). I've reworked this PR to fix this problem and remove the original remounting hack introduced.
JIRA: https://atomlearningltd.atlassian.net/browse/DS-447
JIRA 2: https://atomlearningltd.atlassian.net/browse/DS-469
Basically the bug is that when the DateField is used in combination with validation, once we submit the form and we get to a state of validating
onChange
- typing in the Input field glitches out and eats the letters we are typing as well as backspaces etc.From a day's worth of research/work it looks to me like this might be a bug within
react-hook-form
's validation logic - I have not exactly pinpointed where it is in their code though.All I can tell is our
onChange
does not run when validation happensonChange
(post submit) and the message is about to change. I did not find any github issues reporting on this - the closest I got was this stackoverflow ticket.This is an attempt to fix the reported bug. It is an unorthodox method and kind of a hack - but I could not figure out the proper way to solve this. I'm assuming this is a bug or even expected functionality from
react-hook-form
. This sort of bug I'm also assuming affects any other field which relies on controlled value but is used with validation - perhaps particularly with a validation function.Comments and alternative solutions are welcome.
Edit:
I changed the solution to trigger onChange on the input instead. Which solves the issue with the component not marking as
dirty
when observed via aForm
'sdirtyFields
Tested with sanbox
Videos
before
Screen.Recording.2023-07-19.at.12.12.01.mov
after
Screen.Recording.2023-08-23.at.16.09.03.mov