vee-validate icon indicating copy to clipboard operation
vee-validate copied to clipboard

Schema and rules at the same time

Open dakujem opened this issue 1 year ago • 2 comments

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]

dakujem avatar Nov 23 '22 14:11 dakujem

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.

logaretm avatar Dec 06 '22 20:12 logaretm

Maybe some kind of a warning would bee enough to start with.

dakujem avatar Dec 06 '22 22:12 dakujem