vee-validate
vee-validate copied to clipboard
Schema and rules at the same time
While testing out VeeValidate, I found out I was unable to use both a schema and per-field-assigned rules, which surprised me. If schema is set on the form, the rules are ignored.
In other words, adding a schema to a form effectively disables all existing validation.
<Form @submit="submitHandler" :validation-schema="schema">
<label class="block mb-4">
{{ $t('Last name') }}
<Field name="surname" type="text" :rules="requiredString"/>
<ErrorMessage name="surname"/>
</label>
...
This comes for practical reasons - sometimes there are dynamic fields and it's easier to just write that one special rule outside of the schema.
This is not a dealbreaker for me, it just surprised me that the field-assigned rules simply stop working. I'd suggest to at least adding a warning. Ideally, the rules would be preserved.
[Vue v3, VeeValidate v4.x]
At the moment you can only have field-level or form-level validation. But not both due to the versatility of the validation rules.
You can specify rules in yup
or zod
or native javascript functions or the laravel inspired ones. The problem with those is that is only a handful of those are mergeable.
But I can see the value here, I will try to explore to see if I can introduce a solution here.
Maybe some kind of a warning would bee enough to start with.