How are you guys doing validations in Vuetify? I'm not able to wrap my head around very verbose validation syntax.
I'm using Vuelidate and as per Vuetify's docs, here is how I'd have to implement a simple required field:
Script:
import { required } from 'vuelidate/lib/validators';
computed: {
userNameErrors() {
const errors = []
if (!this.$v.loginForm.userName.$dirty) {
return errors
}
!this.$v.loginForm.userName.required && errors.push('This field is required')
return errors
}
},
validations: {
loginForm: {
userName: {
required
}
}
}
Template:
<v-text-field :label="Username"
prepend-icon="account_circle"
v-model="loginForm.userName"
:error-messages="userNameErrors"
@input="$v.loginForm.userName.$touch()"
@blur="$v.loginForm.userName.$touch()"
:required="true"></v-text-field>
Which I feel is very verbose. I might be doing things wrong way, can anyone tell how have you made this minimalist or short hand?