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

Server validation errors not removed after field change #5938

Closed
fzan opened this issue Feb 19, 2021 · 4 comments · Fixed by #5962
Closed

Server validation errors not removed after field change #5938

fzan opened this issue Feb 19, 2021 · 4 comments · Fixed by #5962

Comments

@fzan
Copy link
Contributor

fzan commented Feb 19, 2021

What you were expecting:

After this merged PR
#5778
I'm expecting that, after an error is returned from server, it will be shown on the field.
That error must disappear after the field value change, because it must be checked again on the server to validate

What happened instead:

After an error is returned from server, it appears correctly on the related field.
But that error remains after the field value change, leaving the field in error state

Steps to reproduce:

  1. Add an error handler like this suggested in documentation:
    https://marmelab.com/react-admin/CreateEdit.html#submission-validation
  2. Having a requested field on server, leave it blank, submit the form and trigger the error.
  3. The field is now correctly in error state
  4. Try to change the content
  5. The fields remain in error state
  6. Fill the server-side required field
  7. If you submit now, with the required field filled, the form gets submitted correctly, but an error snackbar opens (because there are errors on the form on the submission time)
    Environment
  • React-admin version: 3.12.4
  • React version: 16.13.1
  • Browser: Chrome 88.0.4324.150 on Windows 10
@alanpoulain
Copy link
Contributor

Hello,
You need to use https://github.com/ignatevdev/final-form-submit-errors, like it's done in API Platform Admin:
https://github.com/api-platform/admin/blob/5badc1f19024c1800a60431e575219039b86d0b6/src/CreateGuesser.js#L134-L153

React admin could use it by default too, but it needs to be discussed.

@fzan
Copy link
Contributor Author

fzan commented Feb 23, 2021

@alanpoulain your support was absolutely outstanding!
Thanks for pointing me to the right direction!

@fzaninotto
Copy link
Member

@alanpoulain Agreed, this should be by default in react-admin. Would you like to open a PR about it?

@fzan
Copy link
Contributor Author

fzan commented Mar 12, 2021

Hello, sorry to bump this, but i have a question.

The validation errors are shown 1:1 with the field, and that's the expected behaviour and an excellent solution.
However, imagine a form with:
SelectInput A: select the type of next item ( Int, string)
TextInput B: the value regarding the type choosed on input A

Well, now try to imagine that i submit:

A: Type Int
B: value "hello"
and submit.

The server reply with an error on the TextInput B "value not valid".
Now, instead of changing the TextInputB, i change the SelectInput A, to "string"

The error shown on TextInput B is still there, so on submit i will get a correct save, because the form is in a correct state, but because the field is still in error state, i will also get an error in the snackbar.

What do you think about it? @alanpoulain

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

Successfully merging a pull request may close this issue.

4 participants