Skip to content
Source
Sign inSign up
TanStack/form

fieldMeta not set by async validator #2033

Closedliteralpie(GitHub profile, opens in a new tab) opened this issue 1 comment

Describe the bug

If fieldMeta doesn't exist when an async validator runs, it won't be created. (synchronous validators do cause the meta to get created).

If the meta already exists (because you have a form.Field for that field, or because you do something like setFieldValue('age', 2)), the error gets added to the fieldMeta without a problem.

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-form-vxfykhc5?file=src%2Findex.tsx,package.json

Steps to reproduce

  1. Submit the form without clicking anything else. form.errors shows errors at the form level, but "Age Meta" remains empty
  2. Change onSubmitAsync to onSubmit, then submit the form. The meta gets created as expected.

Expected behavior

If errors happen when doing an async validation, the field meta should be created if necessary.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

macOS Safari

TanStack Form adapter

react-form

TanStack Form version

1.28.0

TypeScript version

No response

Additional context

Possibly related to #1460

  1. literalpie(GitHub profile, opens in a new tab)commented

    This issue is a pretty big priority for us because of the way a few things interact:

    1. Yup validators are always async because of this issue. We are using Yup because the way it handles i18n is better for us than Zod.
    2. For compatibility with our old form solution, we use useFormContext to get/set value and state on fields that do not have a form.AppField mounted. I have found that, besides this issues, fieldMeta is the most reliable way to get the error state of fields.

    So I made a PR with a proposed fix for this.

Sign in to join this conversation.