Skip to content
Source
Sign inSign up
TanStack/form

Change from single error message to object or array of errors #431

Send to my agent
Closedcrutchcorn(GitHub profile, opens in a new tab) opened this issue 2 comments

Right now, we only have a single error per field. This seems like it might limit the UX of any app using TanStack Form.

Instead, I'd like to change our validators to return an object or array of errors:

errorMap = {
    onChange: ValidationError,
    onMount: ValidationError,
    onBlur: ValidationError,
}

Or:

errors: [] // As many errors as show up in `onChange`, `onMount`, `onBlur`

If anything, we may want to provide both to the FieldAPI in our react adapter. Something like:

<form.Field
  name="firstName"
  children={(field) => {
    const errArr = field.state.meta.errors // Array of errors
    const errMap = field.state.meta.errorMap; // Object of errors
    const onChangeErr = errMap?.onChange; // string | undefined | null
  }}
/>

Where errors is derived from errorMap as a derived value

  1. crutchcorn(GitHub profile, opens in a new tab) added labelstype: enhancement

  2. crutchcorn(GitHub profile, opens in a new tab) added labelsgood first issue

  3. Going to work on this one. Could I get assigned to this? 🙏

  4. Absolutely! Thank you for contributing 😊

  5. crutchcorn(GitHub profile, opens in a new tab) unassignedcrutchcorn

Sign in to join this conversation.