We can bind our custom value to the single checkbox elements by using true-value and false-value. For example, we can bind the yes value to replace the default true Boolean value with true-value and no to replace the default false Boolean value with false-value:
// src/components/dynamic-values.vue
<input
type="checkbox"
v-model="form.subscribe"
true-value="yes"
false-value="no"
>
export default {
data () {
return {
form: { subscribe: 'no' }
}
},
methods:{
checkForm (e) {
this.errors = []
if (this.form.subscribe !== 'yes') {
this.errors.push('Subscription required')
}
}
}
}
Now, you get a response of yes or no when you send the value of the subscribe input to the server. In the <script> block, we now declare no as the initial value on the subscribe property and validate it in the...