react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

Is it possible to clear form errors programatically?

Open roman-gula opened this issue 1 year ago • 2 comments

Prerequisites

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

  1. I run validation on wizard step A and some errors are shown
  2. I go to another step B, schema is changed and different form without errors is displayed
  3. 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?

roman-gula avatar Feb 04 '24 18:02 roman-gula

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.

MarekBodingerBA avatar Feb 11 '24 17:02 MarekBodingerBA

@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.

heath-freenome avatar Feb 16 '24 20:02 heath-freenome