Skip to content

Field errors array is empty for object fields #1341

@jahirfiquitiva

Description

@jahirfiquitiva

Describe the bug

When having a form field that is an object, the field's meta errors array is empty, but the form errors array is not.

The form errors look like this:

[
  {
    "user.id": [
      {
        "code": "too_small",
        "minimum": 3,
        "type": "string",
        "inclusive": true,
        "exact": false,
        "message": "[Zod] Id requires 3 characters",
        "path": ["user", "id"]
      }
    ],
    "user.username": [
      {
        "code": "invalid_type",
        "expected": "string",
        "received": "null",
        "path": ["user", "username"],
        "message": "Expected string, received null"
      }
    ]
  }
]

Your minimal, reproducible example

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

Steps to reproduce

  1. Create a form with an object as a field
  2. Try accessing the field errors
  3. Access the form errors
  4. See the differences

Expected behavior

The field's errors array should not be empty and instead include the errors with each property of the object

I think the field's error array should look either like this:

[
  {
    "user": [
      {
        "id": [
          {
            "code": "too_small",
            "minimum": 3,
            "type": "string",
            "inclusive": true,
            "exact": false,
            "message": "[Zod] Id requires 3 characters",
            "path": ["user", "id"]
          }
        ]
      },
      {
        "username": [
          {
            "code": "invalid_type",
            "expected": "string",
            "received": "null",
            "path": ["user", "username"],
            "message": "Expected string, received null"
          }
        ]
      }
    ]
  }
]

or like this:

[
  {
    "user": {
      "id": [
        {
          "code": "too_small",
          "minimum": 3,
          "type": "string",
          "inclusive": true,
          "exact": false,
          "message": "[Zod] Id requires 3 characters",
          "path": ["user", "id"]
        }
      ],
      "username": [
        {
          "code": "invalid_type",
          "expected": "string",
          "received": "null",
          "path": ["user", "username"],
          "message": "Expected string, received null"
        }
      ]
    }
  }
]

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

All

TanStack Form adapter

react-form

TanStack Form version

1.1.2

TypeScript version

No response

Additional context

No response

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