Replies: 1 comment 2 replies
-
|
There's no built-in "show one error" helper — TanStack Form intentionally exposes all causes and leaves the display logic to apps. But the pattern is straightforward. Without Since each cause in const displayError =
field.state.meta.errorMap.onChange ?? // currently typing — most current
field.state.meta.errorMap.onBlur ?? // touched and left
field.state.meta.errorMap.onSubmit // submitted invalid
{displayError && <em>{String(displayError)}</em>}Why
The clean solution: If you're open to revisiting the "without import { revalidateLogic, useForm } from '@tanstack/react-form'
const form = useForm({
validationLogic: revalidateLogic({
mode: 'submit', // no live validation before first submit
modeAfterSubmission: 'change', // clear errors as user fixes them after submit
}),
validators: {
onDynamic: yourZodSchema,
},
})With this setup, each field only ever has The One caveat: there's a known bug (#1861) where |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
TanStack Form exposes field validation results by cause via errorMap (onChange, onBlur, onSubmit, etc.), which is flexible, but I’m unsure what the recommended UX pattern is when an app wants to show only one current error per field.
This feels especially difficult with form-level schema validation, because blurring one field can populate onBlur errors for other fields at the same time. Later, when the user starts editing one of those fields, that field may also get onChange validation, so multiple causes can be present in errorMap for the same field. At that point, it’s not obvious which error should be displayed to the user.
Without using onDynamic/revalidateLogic, is there an intended pattern for collapsing errorMap into one displayed field error when using form-level schemas? Or is the expectation that apps implement their own precedence / active-cause tracking on top of errorMap?
Beta Was this translation helpful? Give feedback.
All reactions