react-admin
react-admin copied to clipboard
Server validation error with related fields
What you were expecting: after the application of this: https://github.com/marmelab/react-admin/issues/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
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).
Hello @djhi ,
Here: https://codesandbox.io/s/vigilant-euler-czxdn
You must follow this steps:
- Create a new post
- select the type: not foobar
- type in title: f00bar
- 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
- now change the type in "f00bar"
- 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.
Reproduced, thanks!
you welcome :)
any update on this?
Nope, any help on this would be greatly appreciated
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.