Vuelidate checking for true/false
Asked Answered
T

2

12

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
},
Theology answered 12/10, 2018 at 13:59 Comment(0)
M
24

You can use a simple function:

terms_accepted: {
  checked: value => value === true
}
Morin answered 12/10, 2018 at 14:7 Comment(0)
S
2
terms_accepted: {
  checked: sameAs(true)
}

works for latest vuelidate as of today:

"@vuelidate/core": "^2.0.0",
"@vuelidate/validators": "^2.0.0",
Sumikosumma answered 15/12, 2022 at 17:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.