Skip to content
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

extraErrors not working properly #3757

Closed
4 tasks done
Sourcekot opened this issue Jul 10, 2023 · 4 comments · Fixed by #3772
Closed
4 tasks done

extraErrors not working properly #3757

Sourcekot opened this issue Jul 10, 2023 · 4 comments · Fixed by #3772
Labels

Comments

@Sourcekot
Copy link

Prerequisites

What theme are you using?

mui

Version

5.8.2

Current Behavior

extraErrors not available in transformErrors and focusOnFirstError
extraErrors in arrays not triggering ErrorListTemplate
The ErrorListTemplate is not called again on a submit if the errors didn't change

Expected Behavior

extraErrors should be included in the errors of transformErrors and focusOnFirstError
extraErrors in arrays should trigger ErrorListTemplate
The ErrorListTemplate should be called again on a submit even if the errors didn't change (but I would understand if that behaviour is not wanted)

Steps To Reproduce

https://codesandbox.io/s/bold-wescoff-stm77h

In the codesandbox I'm adding an extraError when the submit button is pressed. You will see that its message is correctly displayed below the field. But there are the following problems with it:

  1. The errors in transformErrors are not containing the extraErrors (errors.length is 0) -> The extraError message is not transformed.
  2. Same for focusOnFirstError. In the codesandbox it is never reached as there is only an extraError and no "real" errors.

You can see that both transformErrors and focusOnFirstError are reached and contain an error if you clear the field and press submit. The default required check is done and it's message will be transformed to "Error transformed". In the console you can see that focusOnFirstError was also reached as it logged the error object.

  1. In the example the added ErrorListTemplate is only called after the first submit and not after any additional submits. In my project it isn't even called once for the extraErrors. I'm guessing that this might be caused by the field being in an array (type: "array", items -> type: "object", properties -> ...) but I couldn't get that to work properly in the codesandbox. I can see in the onSubmit function that there are extraErrors and that they are added correctly. The error messages at the fields are also displayed correctly but somehow the ErrorListTemplate is never called for them.
    But even the behaviour from the codesandbox wouldn't be much better in my project. It might be the wanted behaviour to not call it again if nothing changed but in my case that would be a problem. I'm using a snackbar in the ErrorListTemplate which is only displayed for a few seconds. It will not be displayed again if there where no changes to the errors.

Environment

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

Anything else?

No response

@Sourcekot Sourcekot added bug needs triage Initial label given, to be assigned correct labels and assigned labels Jul 10, 2023
@heath-freenome
Copy link
Member

heath-freenome commented Jul 14, 2023

@Sourcekot You found a small bug with focusOnFirstError that I will be fixing momentarily so that it gets the extraErrors. As for transformErrors, that is only called by the validator-ajv(6|8) on the errors returned from the AJV validator. It is assumed that your extraErrors have already been transformed by whatever means you need for the AJV errors.

@heath-freenome heath-freenome removed the needs triage Initial label given, to be assigned correct labels and assigned label Jul 14, 2023
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jul 14, 2023
Fix rjsf-team#3757 by adding a new `extraErrorsBlockSubmit` prop on `Form`
- Updated the `FormProps` and `Form` for the new `extraErrorsBlockSubmit` flag
- Updated the validation code to detect when the flag is set and there are `extraErrors` and allow the extra error to be focused on
- Updated `form-props` documentation with additional details about `extraErrors` as well as the new prop
- Updated the `CHANGELOG.md` file accordingly switching from a patch to minor release due to the new feature
heath-freenome added a commit that referenced this issue Jul 14, 2023
Fix #3757 by adding a new `extraErrorsBlockSubmit` prop on `Form`
- Updated the `FormProps` and `Form` for the new `extraErrorsBlockSubmit` flag
- Updated the validation code to detect when the flag is set and there are `extraErrors` and allow the extra error to be focused on
- Updated `form-props` documentation with additional details about `extraErrors` as well as the new prop
- Updated the `CHANGELOG.md` file accordingly switching from a patch to minor release due to the new feature
@Sourcekot
Copy link
Author

Sadly my problems were only partially fixed and some new problems now occur:

Codesandbox: https://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: https://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.

@heath-freenome
Copy link
Member

@Sourcekot Can you open a new issue for these? Thanks!

@Sourcekot
Copy link
Author

@Sourcekot Can you open a new issue for these? Thanks!

Of couse, here you go: #3827

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants