Skip to content

Array subfields missing errors in fieldMeta #1460

@juanvilladev

Description

@juanvilladev

Describe the bug

When a user pushes a field using field.pushValue or form.pushFieldValue, errors for the subfields are missing from fieldMeta.

This leads to a really bad state if the new subfield has errors on the form level schema. canSubmit becomes false so they can't submit the form, yet the error cannot be surfaced.

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-form-lntbeysv?file=src%2Findex.tsx

Steps to reproduce

  1. Add a row
  2. Notice canSubmit is now false, yet no error is surfaced
  3. Click "Log all errors" notice that the form has the errors, but is missing from the fieldMeta

Expected behavior

In the UI, I would expect the error is immediately surfaced to the user.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

See StackBlitz, latest version of TSF, valid TS version

TanStack Form adapter

react-form

TanStack Form version

^1.7.0

TypeScript version

No response

Additional context

This happens because we run the validator before the new pushed subfields mount. Since they have not mounted fieldMeta does not exist leading to the difference between the errorMap on the form and field level.

I propose that onMount we always check if the form errorMap contains errors for the field. If so, copy it over.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions