@latest_post
Validate a required boolean in Vue
Required booleans
Let's say you have a checkbox that you need your users to click/check before proceeding ---like accepting some ToS or agreeing to something.
This falls on the realm of form validation, and there is nothing better than Vuelidate for that.
If you already know some Vuelidate you might be tempted to go with something like:
<!-- template... -->
<script>
import { required } from 'vuelidate/lib/validators'
export default {
data () {
return {
hasAccepted: false
}
},
validations: {
hasAccepted: { required }
}
}
</script>
But you just can't use the required validator on a checkbox ---or switch.
That's because it's a boolean.