-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Allow for debouncing live validation (liveValidate) #3616
Comments
@michal-kurz If you look at the implementation of how liveValidate works, you can see that it calls the |
@heath-freenome Thank you very much for you feedback and pointing me to the right direction. I have a lot of work and personal stuff to do right not, but I will get back to it in about two weeks and try to implement this. I made myself a ticket so I don't forget :) |
I just want to affirm that I'm still planning to do this! I will get to it during next workweek :) |
@heath-freenome I apologize for the delay, I was able to get to it much later than I expected. I made a proof of concept for the invalidation debouncing, and it can be found here: https://github.com/michal-kurz/react-jsonschema-form/pull/1/files# It's in no way polished, and in its current state breaks some other functionality, but I wanted to consult it with you to assess whether it's worth continuing on this route. Would you please look at it? It this roughly acceptable as a concept, or did you imagine something else? Here are my takeaways:
|
How do we go on with this, @heath-freenome ? I initially had plans with this - I was hoping for massive performance gains, looking to potentially delegate debounced (async) There's one thing I haven't yet tested and included in my consideration though: We are currently running on |
Prerequisites
What theme are you using?
other
Is your feature request related to a problem? Please describe.
The
liveValidate
prop performs quite well for one-off state changes in our project when using@rjsf/validator-ajv6
(although not with@rjsf/validator-ajv8
for some reason), but it lags when typing on slow machines.Describe the solution you'd like
This would seemingly be solved by giving implementator a choice to debounce the validation (so it would only initiate live validation once the user has not typed anything for X milliseconds).
Describe alternatives you've considered
I tried achieving the same effect by turning off
liveValidation
and calling a debounced instance ofForm.validateForm()
insideonChange
, but it lead to very confusing results for me:liveValidation
actually functions slightly differently fromForm.validateForm()
in what/how it validates - as ifliveValidation
only validated inputs that were actually being rendered, whileForm.validateForm()
always validating all offormData
against all ofschema
- or something in that ballpark. I was getting very different results between these two, andForm.validateForm()
turned out to be terribly incompatible with our legacy code.Form.validateForm()
triggersonError
, whileliveValidation
doesn't. This is a big issue for us, because we use custom logic for un-collapsing collapsed form sections (custom widgets) and scrolling to invalid fieldsonError
. When usingForm.validateForm()
onChange
to simulate live validation, this makes our form scroll all over the place all the time. De-couplingForm.validateForm()
andonError
(maybe allowing forForm.validateForm({ triggerErrorHandler: false })
) might help our use-case greatly.It also might be possible to manually achieve this by wrapping
@rjsf/validator-ajv6
into a custom validator and using debounce somewhere in the way - but I have no idea how to approach this. Do you think that would be possible?Thank you for your consideration 🙏
The text was updated successfully, but these errors were encountered: