[英]Vue / Vuetify text-field Validation depending on checkboxes
vue / vuetify beginner here... vue / vuetify 初学者在这里...
I've got a form that has two checkboxes and a text-field.我有一个包含两个复选框和一个文本字段的表单。
https://jsfiddle.net/tur0gks4/3/ https://jsfiddle.net/tur0gks4/3/
How can I trigger validation of the v-text-field "VIP name" only when one or both of the checkboxes are selected? How can I trigger validation of the v-text-field "VIP name" only when one or both of the checkboxes are selected? If none is selected, I don't want to validate the input field.
如果没有选择,我不想验证输入字段。
I believe I have to change this我相信我必须改变这一点
vip_nameRules: [
v => !!v || 'VIP name required',
],
To something like this对于这样的事情
vip_nameRules: [
v => !!v || 'VIP name required',
v => (!vip_attend && !vip_host) || 'VIP name required',
],
But I can't figure it out... =(但我想不通... =(
thanks谢谢
Make sure your validation rules are a computable like this:确保您的验证规则是可计算的,如下所示:
Vue.use(Vuetify);
var vm = new Vue({
el: "#app",
data: {
vip_attend: false,
vip_host: false,
vip_name: '',
},
computed: {
vip_nameRules () {
const rules = []
if (!this.vip_attend || !this.vip_host) {
const rule = v => !!v || 'VIP name required'
rules.push(rule)
}
return rules;
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.