react-admin
react-admin copied to clipboard
Global validation not firing after submit with ArrayInput
What you were expecting: I have a form with the mode and reValidateMode set to onBlur, when I submit the form the input validation should still fire onBlur.
What happened instead: Once the form has been resubmitted onBlur validation no longer works. The form is only revalidation onSubmit
Steps to reproduce:
- Go to the Sandbox https://codesandbox.io/s/hardcore-edison-ntjjfj?file=/src/posts/PostEdit.tsx:2932-2946
- Enter a word in the top title
- Click save
- Enter text into the errored inputs
- The error messages still remain
Related code: https://codesandbox.io/s/hardcore-edison-ntjjfj?file=/src/posts/PostEdit.tsx:2932-2946
Other information:
Environment
- React-admin version: 4.0.1
- Last version that did not exhibit the issue (if applicable):
- React version: 17.0.2
- Browser: Chrome
- Stack trace (in case of a JS error):
Hi!
Thank you for submitting this.
I reproduced the issue thanks to your codesandbox.
However, I noted that this issue only happens inside an ArrayInput
component. It does not happen when you use plain TextInput
for example. There might be something wrong in the way we handle input identifiers there, I'll need to investigate.
Probably linked to: https://github.com/marmelab/react-admin/issues/7591#issuecomment-1115018804
This issue still happens even after #8080.
I took some time to do some testing around, and now I'm convinced this problem does not come from react-admin but rather from react-hook-form. I opened an issue on their repo: https://github.com/react-hook-form/react-hook-form/issues/8927
Hopefully they will be able to fix it or tell us what we do wrong.
Okay so @bluebill1049 answered and it appears the format of our errors
object is wrong in case of array fields.
We should have
{
test: [{firstName: {....}}]
}
rather than
{"test.0.firstName":{"type":"required","message":"firstName is required."}
This can probably be fixed inside getSimpleValidationResolver.ts