使用元素ui vuejs基于复选框设置所需的不需要的验证

时间:2019-04-16 10:27:27

标签: vue.js element

根据复选框使用元素ui vuejs设置不需要的验证

我有一个代码,其中我想在复选框为yes时设置必填字段的验证,它的名称应该是必需的,否则它是不需要的,并且提及消息也应该消失。

rules: {
          name: [
            { required: !this.delivery, message: 'Please input Activity name', trigger: 'blur' },
            { min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' }
          ],
          region: [
            { required: true, message: 'Please select Activity zone', trigger: 'change' }
          ],
          date1: [
            { type: 'date', required: true, message: 'Please pick a date', trigger: 'change' }
          ],
          date2: [
            { type: 'date', required: true, message: 'Please pick a time', trigger: 'change' }
          ],
          type: [
            { type: 'array', required: true, message: 'Please select at least one activity type', trigger: 'change' }
          ],
          resource: [
            { required: true, message: 'Please select activity resource', trigger: 'change' }
          ],
          desc: [
            { required: true, message: 'Please input activity form', trigger: 'blur' }
          ]
        }

尝试过的代码是我的代码笔 https://codepen.io/Jack_8588/pen/pBpojg

0 个答案:

没有答案