-
Version Number7.48.2 Codesandbox/Expo snackhttps://codesandbox.io/p/sandbox/fieldarray-validation-ww26zl?file=%2FformInput.js Steps to reproduce
Expected behaviourThe newly displayed input fields from the FieldArray are taken into account in the save button state: As long as the fields are empty, the button is disabled. However, as long as the fields are empty, they should have a red background (as is the case with the input field "name", which uses the same FormInput component). When I check the formState.errors the fieldArray fields are not included. What browsers are you seeing the problem on?Chrome, Edge Relevant log outputNo response Code of Conduct
|
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
I don't get your issue in here. |
Beta Was this translation helpful? Give feedback.
-
You're trying to reuse the same input component for both field array fields and plain/object fields ( In the same input component, you are trying to access the error field with I suggest you pass the background color or even the field error from the parent component instead to avoid adding more logic to handle different field types inside the reusable component. |
Beta Was this translation helpful? Give feedback.
-
I've updated the codesandbox example and hope this will help you understand my issue: To reproduce it
So the problem is the initial validation. The validation is triggered as can be seen in the state of the _save_button, but the results are not shown in |
Beta Was this translation helpful? Give feedback.
-
Please see #11568 (comment) |
Beta Was this translation helpful? Give feedback.
-
@Moshyfawn Did you take a look at the updated code example? I've handled accessing errors from the fieldArray in |
Beta Was this translation helpful? Give feedback.
-
@bluebill1049 @Moshyfawn I've reduced my example even further: https://codesandbox.io/p/sandbox/fieldarray-validation-forked-srkmdp?file=%2FTestFormStateError.js. There's no more custom component or colors to be set. The problem remains the same: When I append the fieldArray the new child-element with required-rule is considered for formState.isValid but not listet in formState.errors until I update the child's value To reproduce:
Please let me know what is wrong in this set up or point me to the correct section in the documentation. I couldn't find anything. testformstateerror.mp4 |
Beta Was this translation helpful? Give feedback.
-
I've finally found the solution:
Hence we have to call
|
Beta Was this translation helpful? Give feedback.
I've finally found the solution:
Hence we have to call
trigger
after rendering withuseEffect
: