-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Fix global validation not firing after submit with ArrayInput
#8118
Fix global validation not firing after submit with ArrayInput
#8118
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work! But I think that now that you've done all the digging, we should write down the proper format in the documentation.
Also, do we still need the flattenErrors utility?
values: {}, | ||
errors: { | ||
title: { type: 'manual', message: 'title too short' }, | ||
backlinks: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does one specify errors in some of the items but not all? Does this work?
backlinks: [null, null, { url: { type: 'manual', message: 'url too short' }}, null]
I think it's worth a test.
Edit: I see you've made that test later. Well, it's worth some documentation in ArrayInput and in the global validation section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some documentation. Please tell me if this is enough or if I need to emphasize that returning something like [{}, {}]
is supported
{ url: 'url too short', id: 'missing id' }, | ||
{ url: 'url too short', id: 'missing id' }, | ||
], | ||
describe('flattenErrors', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we flatten in the first place if react-hook-form requires a tree structure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dunno 🤷
I was able to track its origin down to this issue and especially this comment: #7500 (comment)
But as I said I don't know what made you say this at the time. Since this is currently not documented on rhf's side either I can't tell if there was a change on their side or not...
// `type: 'manual'` and a `message` prop like react-hook-form expects it | ||
const transformedErrors = transformErrorFields(errors); | ||
|
||
// If, after transformation, there are no errors, return the form values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this possible? Please elaborate in the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can happen if the validator returns an error object like:
{
backlinks: [{}, {}],
}
in this case we first need to transform the error field to realize it actually contains no errors.
I'll add this in the comment.
Also, needs rebase. |
…ion-not-firing-after-submit-with-arrayinput
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
The added doc is fine! |
Fixes #7594
Todo
getSimpleValidationResolver.ts
according to Global validation not firing after submit with ArrayInput #7594 (comment)Screenshots
Before
After
Additional info
So here is some testing I made by myself:
In RA v3:
validate
's result's shapeIn RA v4 - before this PR:
validate
's result's shapeIn RA v4 - after this PR:
validate
's result's shapeWhere:
{backlinks.1.date: 'A date is required'}
{backlinks: [{}, {date: 'A date is required'}]}