Answer the question
In order to leave comments, you need to log in
Vuelidate - how to check 2 interdependent checkboxes?
Hello everyone, I don’t understand how to do it:
There are 2 checkboxes, the condition is that at least one of them (any) is required
. if at least one is checked, validation passes. If both, then too. If none, then error.
How to explain this vuelidate?
Now I did it like this:
<template>
<input type="checkbox" name="life" id="" v-model="life" @change="$v.life.$touch()">
<label for="life">Жизнь</label>
<input type="checkbox" name="property" id="" v-model="property" @change="$v.property.$touch()">
<label for="life">Имущество</label>
</template>
validations() {
if(!this.property){
return {
life: {
required (val) {
return val
}
},
}
}
if(!this.life){
return {
property: {
required (val) {
return val
}
},
}
}
},
Answer the question
In order to leave comments, you need to log in
One by one works, if you check both, then "Error in v-on handler: "TypeError: Cannot convert undefined or null to object"
validations() {
return {
life: this.property ? {} : { required: v => v },
property: this.life ? {} : { required: v => v },
};
},
<div>STATUS: {{ $v.$invalid ? 'ЖОПА' : 'OK' }}</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question