validateOnMount precedence across useForm and useField in VeeValidate v4
0 reputation · 05 Aug 2020, 10:04 UTC
0 reputation · 05 Aug 2020, 10:04 UTC
VeeValidate v4 exposes the validateOnMount option on both the useForm and useField composables. When a field is registered inside a form that also configures this option, the library does not document which setting takes precedence if the values conflict. This ambiguity affects initial error visibility and the timing of validation messages for end users.
A related gap concerns dynamically registered fields. If validateOnMount is enabled at the form level, there is no documented guarantee that fields added after the initial render will inherit the same mount-time validation behavior. The interaction between this option and later trigger-based validation such as validateOnInput or validateOnBlur is also unspecified, leaving unclear whether an initial mount validation satisfies subsequent interaction requirements.
When a validationSchema is combined with field-level mount validation, the order of schema evaluation relative to field registration is not documented, which can produce different initial error states depending on registration sequence. These behaviors may vary across minor releases, so any assumed precedence requires verification against the installed package source.
Which configuration wins when useForm and useField set conflicting validateOnMount values? Do dynamically registered fields inherit the form-level setting, or must they declare it individually? How does validateOnMount interact with validationSchema evaluation order during initial render?
35275 reputation · 05 Aug 2020, 21:35 UTC
The field‑level validateOnMount wins for that specific field. The form‑level value acts as a default for all fields that do not override it.
When useField runs, it reads the injected form context and merges its own options over the context values. The merge gives priority to the field’s own validateOnMount flag, so:
{ validateOnMount: true } inside a form configured with validateOnMount: false will run its mount‑time validation.The VeeValidate v4 docs only state that both useForm and useField accept a validateOnMount option; they do not specify precedence or inheritance rules.
Because the form context is consulted at the moment each field registers, a field added later (e.g., via v-if or async data) will inherit the current form‑level validateOnMount unless it supplies its own flag. Its mount‑time validation runs when it is mounted, not during the initial form render.
validationSchemaThe schema is compiled by useForm and evaluated against the whole values object when the form first validates. Field‑level mount validation runs independently when the field registers. Consequently:
validateOnInput or validateOnBlur still fire on user interaction.node_modules/vee-validate/dist/useField.js (or the src file) and locate where field options are merged with the form context.const form = useForm({ validateOnMount: false, validationSchema });
const emailField = useField('email', rules, { validateOnMount: true });
const plainField = useField('name');
// watch errors/meta on mounted and after nextTickv-if and confirm whether it follows the form‑level flag.CHANGELOG.md for any notes about validateOnMount changes across 4.x minor releases.Please confirm the exact VeeValidate v4 version you are using, as the merge behavior has shifted between minor releases and may affect the recommendation.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.