-
-
Notifications
You must be signed in to change notification settings - Fork 600
Description
Summary
With zod schema validators on both onMount and onChange, a parent form can remain invalid after a nested value is corrected through a separately managed subform.
The key mismatch is:
form.state.isValid === falseform.state.errors.length === 0form.state.errorMapis empty
At the same time, the tracked parent field still has a stale onMount error in its meta.
Reproduction
StackBlitz repro:
https://stackblitz.com/edit/vitejs-vite-ehbcczvw?file=src%2FApp.tsx
The repro uses:
- a parent form with
person.name - a separate child/subform with
name zodschemas assigned to bothonMountandonChange- subform sync via
parentForm.setFieldValue('person', formApi.state.values)followed byparentForm.validate('change')
Actual behavior
After typing a valid name in the subform, the parent form shows:
{
"values": {
"person": {
"name": "peter"
}
},
"isValid": false,
"canSubmit": false,
"errors": [],
"errorMap": {}
}isValid is false, but the form-level errors are empty.
The parent tracked field meta still contains the stale error:
{
"isTouched": false,
"isValid": false,
"errors": [
{
"origin": "string",
"code": "too_small",
"minimum": 1,
"inclusive": true,
"path": [
"person",
"name"
],
"message": "Name is required"
}
],
"errorMap": {
"onMount": [
{
"origin": "string",
"code": "too_small",
"minimum": 1,
"inclusive": true,
"path": [
"person",
"name"
],
"message": "Name is required"
}
]
}
}Expected behavior
These should stay in sync:
- if the form reports
errors: []anderrorMap: {},isValidshould betrue - or, if the field meta is still invalid because of a tracked
onMounterror, the parent form should reflect that invalid state in its own visible error state
Right now the parent form state and the tracked field meta disagree.
Additional note
I also reproduced the same behavior in a local form-core test using zod schemas and a parent/subform sync pattern. The failing condition is specifically that parent form errors clear while the tracked child field retains a stale onMount error.