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 error with related fields #6104

Closed
fzan opened this issue Mar 31, 2021 · 7 comments
Closed

Server validation error with related fields #6104

fzan opened this issue Mar 31, 2021 · 7 comments
Labels

Comments

@fzan
Copy link
Contributor

fzan commented Mar 31, 2021

What you were expecting:
after the application of this:
#5938
in 3.13.2, React-admin handle the server side validation errors.
When a field is reported by the server with a validation error, it correctly show the error.

What happened instead:
The behaviour is correct:

  • when the error is related only to one specific field
  • when the error is related to multiple fields but with no direct "logical" relation

but, when the fields are dependants, the form handling logic fails.
To better explain what i mean, please follow the example below

Steps to reproduce:

Let's try a form with:
SelectInput A: select the type of next item ( int, string)
TextInput B: the value regarding the type choosed on input A

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", because the type and the value doesn't match.
The first field is correct because it can only choose from a static list of values.
Now, instead of changing the TextInputB, i change the SelectInput A, to "string"

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

Other information:
imho the issue could be handled in this way:
Every change to the form will reset the server errors form-wide.
That's because the logic, in this scenario, is handled by the server and any modification can change the form validity, disregarding the 1-1 server-form field error type

The other way is, sadly, to disable the server side validation and handle the validation logic via frontend.

Environment

  • React-admin version: 3.13.2
  • Last version that did not exhibit the issue (if applicable):
  • React version: 17.0.2
  • Browser: unrelated
@djhi
Copy link
Collaborator

djhi commented Apr 9, 2021

Thanks for reporting this. Please provide a sample application showing the issue by forking the following CodeSandbox (https://codesandbox.io/s/github/marmelab/react-admin/tree/master/examples/simple).

@fzan
Copy link
Contributor Author

fzan commented Apr 9, 2021

Hello @djhi ,

Here:
https://codesandbox.io/s/vigilant-euler-czxdn

You must follow this steps:

  1. Create a new post
  2. select the type: not foobar
  3. type in title: f00bar
  4. save

This will trigger the "server side validation" error: bad title (i used my actual wrapper for create and edit)
The error is correctly shown on the form

  1. now change the type in "f00bar"
  2. submit again

this will trigger the save, but this time the form is valid and is submitted.
However, an error snackbar appears because there is one or more field that was in error state.

@fzaninotto
Copy link
Member

Reproduced, thanks!

@fzan
Copy link
Contributor Author

fzan commented Apr 30, 2021

you welcome :)

@fzan
Copy link
Contributor Author

fzan commented Jul 1, 2021

any update on this?

@djhi
Copy link
Collaborator

djhi commented Jul 2, 2021

Nope, any help on this would be greatly appreciated

@WiXSL WiXSL added the v3 label Nov 2, 2022
@fzaninotto
Copy link
Member

With the release of react-admin v5, react-admin v3 has reached its end of life. We won't fix bugs or make any new release on the 3.x branch. We recommend that you switch to a more recent version of react-admin.

So I'm closing this issue as we won't fix it.

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

No branches or pull requests

4 participants