fix(Form): improve nested form validation handling#5024
Conversation
commit: |
0fc2386 to
af3ee88
Compare
| if (matchesTarget(name, form.name)) form.api.clear() | ||
| nestedErrors.push(...getFormErrors(form as any)) |
There was a problem hiding this comment.
| if (matchesTarget(name, form.name)) form.api.clear() | |
| nestedErrors.push(...getFormErrors(form as any)) | |
| if (matchesTarget(name, form.name)) { | |
| form.api.clear() | |
| } else { | |
| nestedErrors.push(...getFormErrors(form as any)) | |
| } |
The clear method collects errors from all nested forms regardless of whether they were actually cleared, potentially reintroducing errors that should have been cleared.
View Details
Analysis
Inconsistent error collection in Form.clear() method
What fails: Form.clear() collects errors from ALL nested forms instead of only non-cleared forms, inconsistent with setErrors() pattern
How to reproduce:
- Create parent form with multiple nested forms containing errors
- Call
parentForm.clear('specificFormName')to clear only one nested form - Observe that
getFormErrors()is called on all forms, including the just-cleared form
Result: Unnecessary getFormErrors() calls on cleared forms that return empty arrays
Expected: Only collect errors from forms that were NOT cleared, matching the pattern used in setErrors() method where only targeted forms are processed
Reference: The setErrors() method in the same file only collects errors from matched forms within the conditional block, but clear() collects from all forms unconditionally
There was a problem hiding this comment.
The method used here collects the latest errors, so it excludes errors that have been cleared.
🔗 Linked issue
Resolves #5013
❓ Type of change
📚 Description
Refactors the nested form logic inside the form component and fixes an issue where using
FormFieldwithout an input would not display errors.📝 Checklist