Search code examples
javascriptvue.jsnuxt.jsvuelidate

Vuelidate does not work correctly when the data model is different from validations model


When the data model is different from validations model, required and minLength are not validating correctly. https://jsfiddle.net/2vs9kdb3/4/


<input v-model="text" @blur="$v.form.text.$touch()" :class="{ 'is-invalid': $v.form.text.$error }">
<template v-if="!$v.form.text.minLength">
    Text is too short
</template>


....


data: {
    text: ''
},

validations: {
    form: {
        text: {
        required,
        minLength: minLength(5)
        }
    }
}
 

Solution

  • Although it is not stated in the docs the validations structure must be the same as the data model.