Only validate touched/dirty fields #1722
Answered
by
LeCarbonator
Micnubinub
asked this question in
General
-
What's the best way to validate only the dirty fields in const form = useAppForm({
canSubmitWhenInvalid: false,
defaultValues: {
val1: '',
val2: ''
} ,
validators: {
onBlur: Schema
}
})
<form.AppForm>
<form.AppField
name='val1'
children={(field) => (
<field.TextInput label='V 1' />
)}
/>
<form.AppField
name='val1'
children={(field) => (
<field.TextInput label='V 2' />
)}
/>
</form.AppForm> |
Beta Was this translation helpful? Give feedback.
Answered by
LeCarbonator
Sep 9, 2025
Replies: 1 comment
-
There's two requirements you have for showing errors:
Since you're using field components, you should use const isTouched = useStore(field.store, state => state.meta.isTouched)
const submissionAttempts = useStore(field.form.store, state => state.submissionAttempts)
const showError = isTouched || submissionAttempts > 0 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Micnubinub
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's two requirements you have for showing errors:
isTouched
: It must be touched (blurred or changed). If it should only be blurred, useisBlurred
instead.submissionAttempts > 0
Since you're using field components, you should use
useStore
to ensure it's reactive.