react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

Server validation error with related fields

Open fzan opened this issue 3 years ago • 6 comments

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

fzan avatar Mar 31 '21 07:03 fzan

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).

djhi avatar Apr 09 '21 09:04 djhi

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.

fzan avatar Apr 09 '21 13:04 fzan

Reproduced, thanks!

fzaninotto avatar Apr 29 '21 19:04 fzaninotto

you welcome :)

fzan avatar Apr 30 '21 07:04 fzan

any update on this?

fzan avatar Jul 01 '21 13:07 fzan

Nope, any help on this would be greatly appreciated

djhi avatar Jul 02 '21 09:07 djhi

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.

fzaninotto avatar Jul 02 '24 08:07 fzaninotto