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
},
LeBlaireau
  • 17,133
  • 33
  • 112
  • 192

2 Answers2

22

You can use a simple function:

terms_accepted: {
  checked: value => value === true
}
Giovane
  • 1,421
  • 1
  • 15
  • 25
1
terms_accepted: {
  checked: sameAs(true)
}

works for latest vuelidate as of today:

"@vuelidate/core": "^2.0.0",
"@vuelidate/validators": "^2.0.0",
Alexander Kim
  • 17,304
  • 23
  • 100
  • 157