I have a custom checkbox
<checkbox v-model="form.terms_accepted" />
The true/false value toggles fine
{
"first_name": "",
"last_name": "", "username": "",
"email": "", "terms_accepted": true
}
How do I validate for a true value?
at the moment I my validation rule is.
terms_accepted: {
required
},
Using Vuelidate you can reset the validation errors by using this. $v. $reset() . In this Codepen example resetting the lastName field that uses a Vuetify component works - $invalid is true while $error is set to false.
Vuelidate 2 is a simple, but powerful, lightweight model-based validation for Vue. js 3 and 2. Vuelidate is considered model-based because the validation rules are defined next to your data, and the validation tree structure matches the data model structure. Vuelidate v2.0 supports both Vue 3.0 and Vue 2.x**
All you need is to add the v-validate directive to the input you wish to validate and make sure your input has a name attribute for error messages generation. Then, pass to the directive a rules string which contains a list of validation rules separated by a pipe ' | '.
You can use a simple function:
terms_accepted: {
checked: value => value === true
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With