Skip to content

prefixSchemaToErrors does not support paths for arrays of objects #1683

@dlindahl

Description

@dlindahl

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

  1. Go to https://stackblitz.com/edit/tanstack-form-zzmhzozz?file=src%2Findex.tsx
  2. Note that there are no errors on the form
  3. Click "Add Person"
  4. Note that the form's validations are run on button click
  5. Note that the title field has a field-specific validation message AND the validation message is present in the state.errors and state.errorMap values that are rendered at the bottom of the page.
  6. Note that the people[0].name field HAS NO field-specific validation message AND the validation message is present in the state.errors and state.errorMap values that are rendered at the bottom of the page. This is due to the error path not matching the field name due to how prefixSchemaToErrors reconstitutes 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

Image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions