Capítulo 9 de 29
onDynamic (paired with revalidateLogic()) lets a form validate differently before vs. after the user's first submit attempt — the standard pattern for "don't nag on every keystroke until they've tried to submit once."
revalidateLogic({ mode, modeAfterSubmission }): mode controls validation timing before the first submit ('submit'/'blur'/'change'); modeAfterSubmission controls it after.onDynamic/onDynamicAsync: the validator(s) that actually run under this dynamic logic, settable at field or form level.form.state.errorMap.onDynamic, distinct from the plain onChange/onBlur/onSubmit error maps.onDynamic composes with the other timing validators (ch008) — it's an additional mode, not a replacement.const form = useForm({
defaultValues: { firstName: '', lastName: '' },
validationLogic: revalidateLogic({
mode: 'submit', // before first submit: only validate on submit
modeAfterSubmission: 'blur', // after first submit: validate on blur
}),
validators: {
onDynamic: ({ value }) => {
if (!value.firstName) return { firstName: 'Required' }
return undefined
},
},
})
revalidateLogic() explicitly set as validationLogic — onDynamic does nothing without it.hasSubmitted flag and branching your onChange validator yourself.onDynamic errors live in a separate map (errorMap.onDynamic) from onChange/onBlur/onSubmit errors — check the right map when debugging why an error isn't showing.onDynamic layers on top of.submissionAttempts/isSubmitted state this pattern typically keys off conceptually.