异步验证器在提交表单之前避免验证
async-validator avoid validation before submitting form
我用async-validator combined with element-ui.
我只想在提交表单时执行验证(实际上我在代码中这样做)。
在 rules
定义中使用 trigger: 'change'
时,如果我留下一个不符合规则的值的字段,我会收到一条错误消息:
name: [
{ required: true, message: 'Required field', trigger: 'blur' },
{ min: 5, message: 'Name should have at least 5 letters\n', trigger: 'change' }
],
使用 trigger: 'blur'
时,我什至在离开字段之前收到一条错误消息:
name: [
{ required: true, message: 'Required field', trigger: 'blur' },
{ min: 5, message: 'Name should have at least 5 letters\n', trigger: 'blur' }
],
我尝试使用 validate-on-rule-change
,但没有用:
<el-form ref="addressForm" :inline="true"
:model="formData" :rules="addressRules" class="demo-form-inline"
:validate-on-rule-change="false"
>
也许可以改变你的规则,让你在里面有一个触发器:
required_blur: {
required: true,
message: "Donnée obligatoire",
trigger: 'blur' // When focus changes in the input it triggers
},
required_change: {
required: true,
message: "Donnée obligatoire", // When input's value changes
trigger: 'change'
},
祝你好运:)
你可以简单地做
name: {
required: true,
message: "Please enter name ",
trigger: 'submit' // Only triggers when $refs.form.validate() is called
},
我用async-validator combined with element-ui.
我只想在提交表单时执行验证(实际上我在代码中这样做)。
在 rules
定义中使用 trigger: 'change'
时,如果我留下一个不符合规则的值的字段,我会收到一条错误消息:
name: [
{ required: true, message: 'Required field', trigger: 'blur' },
{ min: 5, message: 'Name should have at least 5 letters\n', trigger: 'change' }
],
使用 trigger: 'blur'
时,我什至在离开字段之前收到一条错误消息:
name: [
{ required: true, message: 'Required field', trigger: 'blur' },
{ min: 5, message: 'Name should have at least 5 letters\n', trigger: 'blur' }
],
我尝试使用 validate-on-rule-change
,但没有用:
<el-form ref="addressForm" :inline="true"
:model="formData" :rules="addressRules" class="demo-form-inline"
:validate-on-rule-change="false"
>
也许可以改变你的规则,让你在里面有一个触发器:
required_blur: {
required: true,
message: "Donnée obligatoire",
trigger: 'blur' // When focus changes in the input it triggers
},
required_change: {
required: true,
message: "Donnée obligatoire", // When input's value changes
trigger: 'change'
},
祝你好运:)
你可以简单地做
name: {
required: true,
message: "Please enter name ",
trigger: 'submit' // Only triggers when $refs.form.validate() is called
},