Merge pull request #437 from tengmaoqing/form-empty-fields

fix: 解决props为空,验证表单没响应的问题
This commit is contained in:
Aresn 2020-06-23 17:29:01 +08:00 committed by GitHub
commit 64772343f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View file

@ -169,6 +169,24 @@
</FormItem>
</Form>
</i-col>
<i-col span="6">
<Form :model="formValidate5" ref="formValidate5">
<FormItem label="name" prop="name">
<Input v-model="formValidate5.name" placeholder="Enter your name"></Input>
</FormItem>
<FormItem label="name">
<i-switch v-model="formValidate5.msgCheck" />
</FormItem>
<FormItem label="msg" v-if="formValidate5.msgCheck" prop="msg" :rules="[{
required: true
}]" >
<Input v-model="formValidate5.msg" placeholder="msg"></Input>
</FormItem>
<FormItem>
<Button type="primary" @click="handleSubmit('formValidate5')">Submit</Button>
</FormItem>
</Form>
</i-col>
</row>
<div style="margin: 100px;width: 200px;">
<Divider>普通组件</Divider>
@ -284,6 +302,11 @@
rate: 3,
colorPicker: ''
},
formValidate5: {
name: '',
msgCheck: false,
msg: ''
},
ruleValidate: {
name: [
{ required: true, message: 'The name cannot be empty', trigger: 'blur' }

View file

@ -91,6 +91,13 @@
return new Promise(resolve => {
let valid = true;
let count = 0;
// fields promise
if (this.fields.length === 0) {
resolve(valid);
if (typeof callback === 'function') {
callback(valid);
}
}
this.fields.forEach(field => {
field.validate('', errors => {
if (errors) {