rjsf-team/react-jsonschema-form

Issues with focusOnFirstError and onSubmit

Open

#3827 opened on Aug 14, 2023

View on GitHub
 (3 comments) (0 reactions) (0 assignees)TypeScript (13,175 stars) (2,136 forks)batch import
awaiting responsebughelp wantedvalidation

Description

Prerequisites

What theme are you using?

mui

Version

5.12.0

Current Behavior

Follow-up to https://github.com/rjsf-team/react-jsonschema-form/issues/3757: Sadly my problems were only partially fixed and some new problems now occur:

Codesandbox: codesandbox.io/s/solitary-breeze-7ykd2f

  1. focusOnFirstError is only reached when I'm pressing submit for a second time.
  2. onSubmit is only called once, try the following in the codesandbox: Fill the field and press submit, it will show "ExtraError field filled.". Now clear the field and press submit again and the message doesn't change (should have been "ExtraError field not filled."). The console.log in the first line of onSubmit is never reached.
  3. If the first error is inside an array the error in focusOnFirstError will be "undefined". See codesandbox: codesandbox.io/s/quizzical-butterfly-zsh7v7 Add a subentry and press submit. It will somehow close after the first submit so add a subentry again and submit again. This time you can see "undefined" in the console as the error object from the focusOnFirstError function.

One more thing: Why is the ErrorListTemplate reached every time I change something in the form? LiveValidate is not enabled so I thought this shouldn't happen.

Expected Behavior

  1. focusOnFirstError should be called at each submit
  2. onSubmit should be called on each submit
  3. focusOnFirstError should work with arrays.

Steps To Reproduce

see Current Behavior section.

Environment

- OS: Microsoft Windows 10 Pro, Version	10.0.19044 Build 19044
- Node: 16.15.0
- npm: 8.18.0

Anything else?

No response

Contributor guide