Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vuelidate checking for true/false

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
},
like image 774
LeBlaireau Avatar asked Oct 12 '18 13:10

LeBlaireau


People also ask

How do I reset my Vuelidate?

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.

What is Vuelidate?

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**

How do you use V validation?

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 ' | '.


1 Answers

You can use a simple function:

terms_accepted: {
  checked: value => value === true
}
like image 130
Giovane Avatar answered Sep 30 '22 05:09

Giovane