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
issue: Array error does not update on a change if any of its fields have errors #10139
Comments
Array error will not get updated by |
The issue I am describing is that appends and removes on the array are sometimes not revalidating the array. This appears to be a bug. |
Please do your own debugging: https://react-hook-form.com/api/useform/
see if the validation schema return the correct output. validation will always gets executed after each action: https://github.com/react-hook-form/react-hook-form/blob/master/src/useFieldArray.ts#L323-L361 |
I have now confirmed using the debug logging that the validation is executed and returns the correct output on steps 6 and 8, but the displayed error does not change until the form is submitted. The CodeSandbox link has been updated to include the debug logging. The problem seems to be with line 329 in |
thanks for looking close into this issue, could you debug further on this since you are already deep into the issue, and find out the root cause? If it's possible to send over a PR would be even greater. |
I will see what I can do. |
This comment was marked as spam.
This comment was marked as spam.
hey @kylemclean could you share more detail on the origin issue? I test above seems to work fine. I will look into it this weekend. |
@bluebill1049 Please also see my comment on #10207 (comment), which might help demonstrate why my PR #10150 resulted in #10207 appearing. |
…pdating in some cases (react-hook-form#10150)" This reverts commit c1cb992.
Version Number
7.43.7
Codesandbox/Expo snack
https://codesandbox.io/s/wispy-surf-znf62c?file=/src/App.tsx
Steps to reproduce
Go to CodeSandbox.
Click "Submit" to start displaying validation errors on change.
Click "Add" button to add an element to the array, causing the array length to be too long, and the error "Form error: Array must contain at most 3 element(s)" to correctly appear.
Click "Remove" next to the newly-added element to remove it, causing the array length to be valid, thus causing the error to correctly disappear.
Delete all of the text in one of the existing array elements, making it invalid and causing an error to correctly appear.
Click the "Add" button again to add another element to the array.
INCORRECT BEHAVIOR: even though the array length is no longer valid, the error from before, "Form error: Array must contain at most 3 element(s)", is NOT being displayed.
Click the "Submit" button, which causes the expected error "Form error: Array must contain at most 3 element(s)" to correctly display.
Click "Remove" next to the newly-added element, causing the array length to be valid.
INCORRECT BEHAVIOR: even though the array length is now valid, the error "Form error: Array must contain at most 3 element(s)" is still incorrectly being displayed.
Click the "Submit" button, which causes the incorrect error "Form error: Array must contain at most 3 element(s)" to disappear.
Expected behaviour
On step 6, clicking the "Add" button should immediately display the error "Form error: Array must contain at most 3 element(s)" instead of requiring the form to be submitted to display it.
On step 8, clicking the "Remove" button should immediately hide the error "Form error: Array must contain at most 3 element(s)" instead of requiring the form to be submitted to hide it.
What browsers are you seeing the problem on?
Firefox, Chrome
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: