Skip to content

Form-level validation with onChange and arrays throws an undefined errorMap #1709

@stefan-huck

Description

@stefan-huck

Describe the bug

Form-level validation with onChange and arrays throws an undefined errorMap when all fields are deleted or when a single field is removed. This issue only occurs with form-level validation using the onChange validator.

Uncaught TypeError: Cannot read properties of undefined (reading 'errorMap')
    at @tanstack_react-form.js?v=473e5c45:1136:27
    at functionalUpdate (@tanstack_react-form.js?v=473e5c45:423:42)
    at @tanstack_react-form.js?v=473e5c45:1349:22
    at Store.setState (@tanstack_react-form.js?v=473e5c45:296:22)
    at FormApi.setFieldMeta (@tanstack_react-form.js?v=473e5c45:1344:22)
    at @tanstack_react-form.js?v=473e5c45:1133:20
    at batch (@tanstack_react-form.js?v=473e5c45:255:5)
    at FormApi.validateSync (@tanstack_react-form.js?v=473e5c45:1090:7)
    at FieldApi.validate (@tanstack_react-form.js?v=473e5c45:2205:97)
    at FormApi.validateField (@tanstack_react-form.js?v=473e5c45:1080:28)

Your minimal, reproducible example

https://stackblitz.com/edit/vitejs-vite-egzzxehs?file=src%2FApp.tsx

Steps to reproduce

  1. Make a change in the form to trigger onChange event (you must see validation error for both fields)
Image
  1. Click on clear all or clean one
  2. See console logs

TanStack Form version

1.19.2

TypeScript version

5.8.3

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