React-jsonschema-form: Errors are not cleared on resubmit, in controlled Form (@rjsf/material-ui)

Created on 26 Aug 2020  路  3Comments  路  Source: rjsf-team/react-jsonschema-form

Prerequisites

Description

When submitting the form, the previous errors are not cleared, although they are fixed.

This only happen if you use a controlled Form (from @rjsf/material-ui: 2.3.0). Uncontrolled Form works as expected.

Possible regression, as this has been reported before and since fixed (the linked sandbox in that issue no longer reproduces the problem).

Steps to Reproduce

  1. Open CodeSandbox demo
  2. Use the controlled form
  3. Click submit (Shows error message)
  4. Fix error (e.g write Jon)
  5. Click submit (Still shows error message)

Expected behavior

Displayed error message should go away on submit if there are no errors.

Actual behavior

Displayed error message persists.

PS: onSubmit is called and event.errors is correctly empty: [].

Version

2.3.0

@rjsf/core: 2.3.0
@rjsf/material-ui: 2.3.0

Most helpful comment

This seems to be introduced in 2.0.1. I've reverted back to v 2.0.0 and it started working again. Probable commit for this behavior change would be https://github.com/rjsf-team/react-jsonschema-form/commit/72963385db4753243d134641709b7a47930a4687

All 3 comments

A usable workaround for this problem is to set the prop liveValidate. Live validation correctly updates error messages, as opposed to only validating on submit.

(I prefer to enable liveValidate once the user has clicked submit, to avoid showing error messages before they have started filling out the form.)

CodeSandbox demo.

I've also recently encountered this issue in the @rjsf/core Form component. In my case, I'm presenting async server errors with the extraErrors prop as described in the docs. However, if there are any schema validation errors (which are then corrected) before the submit button is clicked again and onSubmit is handled, those aren't cleared.

This seems to be introduced in 2.0.1. I've reverted back to v 2.0.0 and it started working again. Probable commit for this behavior change would be https://github.com/rjsf-team/react-jsonschema-form/commit/72963385db4753243d134641709b7a47930a4687

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jabaren picture jabaren  路  3Comments

FBurner picture FBurner  路  3Comments

MedinaGitHub picture MedinaGitHub  路  3Comments

abhishekpdubey picture abhishekpdubey  路  3Comments

anttivikman picture anttivikman  路  3Comments