Skip to content

field.errors incorrectly nested when calling form.validate('change') manually #1993

@swushi

Description

@swushi

Describe the bug

When calling form.validate('change') manually (e.g., after mounting conditional fields), field.errors contains a different structure than when validation runs through normal onChange events.

  • Normal onChange validation: field.errors = [{ "code": "too_small", ...restOfZodError }]
  • Manual form.validate('change') call: field.errors = [[{ "code": "too_small", ...restOfZodError }]]

The errors are wrapped in an extra array when using the manual validate call.

Your minimal, reproducible example

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

Steps to reproduce

  1. Click checkbox to mount conditional fields
  2. Expect error to show up, but error is wrapped in array (see logs for more info)

Expected behavior

For errors from form.validate(...) to have the same output as an organic change event. I'd expect to see an error immediately after clicking the checkbox.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • Stackblitz
  • Mac

TanStack Form adapter

react-form

TanStack Form version

1.27.7

TypeScript version

No response

Additional context

Chatting through this in Discord as well: convo

It also seems like if mount, unmount, then mount again, form.validate(...) produces the correct result.

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