react-jsonschema-form
react-jsonschema-form copied to clipboard
Is it possible to clear form errors programatically?
Prerequisites
- [X] I have read the documentation
What theme are you using?
core
What is your question?
I use rjsf
in form wizard and depending on step I change schema in the form.
Wizard allows to move to different steps even if previous forms was not filled or with errors. If step has some errors, values with errors are not populated to the form data.
When
- I run validation on wizard step A and some errors are shown
- I go to another step B, schema is changed and different form without errors is displayed
- I return back to the step A
the errors are still visible
But I need clear errors before (or after) moving to another step
So is it possible to clear errors programatically?
We also have multistep form and we force re-rendering of the form component using key
. Maybe that would help you.
https://github.com/bratislava/konto.bratislava.sk/blob/8b0be6ed18c39e2a3fee28bcb0a3fcf90a8b9b1e/next/components/forms/FormPage.tsx#L59
However, it's a good question how should the form component behave when schema is changed.
@roman-gula @MarekBodingerBA It totally makes sense for the Form
to detect a change in the schema and reset its state. That currently does not happen. Would either of you be interested in making a PR to fix this? It would involve updating the Form
in core
(probably the getSnapshotBeforeUpdate()
, componentDidUpdate()
and getStateFromProps()
functions) to reset state when the old and new schema props are different.
In the meantime, if you have a ref to the form, you should be able to call the reset()
function.