-
-
Notifications
You must be signed in to change notification settings - Fork 534
Description
Describe the bug
Given a form that represents an array of objects such as { people: [ { name: 'Alex' } ] }, the name field name would be people[0].name.
When the form is validated with a library that supports Standard Schema, the validator will return something along the lines of:
{
issues: {
message: 'This field is required.',
path: ['people', '0', 'name']
}
}
However, when prefixSchemaToErrors processes that validation value, prefixSchemaToErrors returns the path "people.0.name" and then uses that string to hold the validation message in formApi.state.errors. The field will not render the validation message because the key does not match the field name.
Your minimal, reproducible example
https://stackblitz.com/edit/tanstack-form-zzmhzozz?file=src%2Findex.tsx
Steps to reproduce
- Go to https://stackblitz.com/edit/tanstack-form-zzmhzozz?file=src%2Findex.tsx
- Note that there are no errors on the form
- Click "Add Person"
- Note that the form's validations are run on button click
- Note that the
titlefield has a field-specific validation message AND the validation message is present in thestate.errorsandstate.errorMapvalues that are rendered at the bottom of the page. - Note that the
people[0].namefield HAS NO field-specific validation message AND the validation message is present in thestate.errorsandstate.errorMapvalues that are rendered at the bottom of the page. This is due to the error path not matching the field name due to howprefixSchemaToErrorsreconstitutes the path.
Expected behavior
prefixSchemaToErrors should return the path "people[0].name" to match the implied naming standard in @tanstack/form.
How often does this bug happen?
Every time
Screenshots or Videos
Platform
Version 138.0.7204.185 (Official Build) (arm64)
TanStack Form adapter
react-form
TanStack Form version
1.15.1
TypeScript version
No response
Additional context
Additionally, I'd love to see something that indicates what the expected format is for non-trivial field names to make this clearer.