fixed #768
This commit is contained in:
parent
c5625bfdba
commit
05e2dda017
2 changed files with 27 additions and 66 deletions
|
@ -1,78 +1,32 @@
|
||||||
<template>
|
<template>
|
||||||
<div style="width: 300px;">
|
<div style="width: 300px;">
|
||||||
<Form ref="formCustom" :model="formCustom" :rules="ruleCustom" :label-width="80">
|
<i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
|
||||||
<Form-item label="密码" prop="passwd">
|
<Form-item label="爱好" prop="interest">
|
||||||
<Input type="password" v-model="formCustom.passwd"></Input>
|
<Checkbox-group v-model="formValidate.interest">
|
||||||
</Form-item>
|
<Checkbox label="吃饭"></Checkbox>
|
||||||
<Form-item label="确认密码" prop="passwdCheck">
|
<Checkbox label="睡觉"></Checkbox>
|
||||||
<Input type="password" v-model="formCustom.passwdCheck"></Input>
|
<Checkbox label="跑步"></Checkbox>
|
||||||
</Form-item>
|
<Checkbox label="看电影"></Checkbox>
|
||||||
<Form-item label="年龄" prop="age">
|
</Checkbox-group>
|
||||||
<Input type="text" v-model="formCustom.age" number></Input>
|
|
||||||
</Form-item>
|
</Form-item>
|
||||||
<Form-item>
|
<Form-item>
|
||||||
<Button type="primary" @click="handleSubmit('formCustom')">提交</Button>
|
<i-button type="primary" @click="handleSubmit('formValidate')">提交</i-button>
|
||||||
<Button type="ghost" @click="handleReset('formCustom')" style="margin-left: 8px">重置</Button>
|
<i-button type="ghost" @click="handleReset('formValidate')" style="margin-left: 8px">重置</i-button>
|
||||||
</Form-item>
|
</Form-item>
|
||||||
</Form>
|
</i-form>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
data () {
|
data () {
|
||||||
const validatePass = (rule, value, callback) => {
|
|
||||||
if (value === '') {
|
|
||||||
callback(new Error('请输入密码'));
|
|
||||||
} else {
|
|
||||||
if (this.formCustom.passwdCheck !== '') {
|
|
||||||
// 对第二个密码框单独验证
|
|
||||||
this.$refs.formCustom.validateField('passwdCheck');
|
|
||||||
}
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const validatePassCheck = (rule, value, callback) => {
|
|
||||||
if (value === '') {
|
|
||||||
callback(new Error('请再次输入密码'));
|
|
||||||
} else if (value !== this.formCustom.passwd) {
|
|
||||||
callback(new Error('两次输入密码不一致!'));
|
|
||||||
} else {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const validateAge = (rule, value, callback) => {
|
|
||||||
if (!value) {
|
|
||||||
return callback(new Error('年龄不能为空'));
|
|
||||||
}
|
|
||||||
// 模拟异步验证效果
|
|
||||||
setTimeout(() => {
|
|
||||||
if (!Number.isInteger(value)) {
|
|
||||||
callback(new Error('请输入数字值'));
|
|
||||||
} else {
|
|
||||||
if (value < 18) {
|
|
||||||
callback(new Error('必须年满18岁'));
|
|
||||||
} else {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 2000);
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
formCustom: {
|
formValidate: {
|
||||||
passwd: '',
|
interest: ['吃饭', '跑步']
|
||||||
passwdCheck: '',
|
|
||||||
age: ''
|
|
||||||
},
|
},
|
||||||
ruleCustom: {
|
ruleValidate: {
|
||||||
passwd: [
|
interest: [
|
||||||
{ validator: validatePass, trigger: 'blur' }
|
{ required: true, type: 'array', min: 1, message: '至少选择一个爱好', trigger: 'change' },
|
||||||
],
|
{ type: 'array', max: 2, message: '最多选择两个爱好', trigger: 'change' }
|
||||||
passwdCheck: [
|
|
||||||
{ validator: validatePassCheck, trigger: 'blur' }
|
|
||||||
],
|
|
||||||
age: [
|
|
||||||
{ validator: validateAge, trigger: 'blur' }
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,10 +191,17 @@
|
||||||
|
|
||||||
let prop = getPropByPath(model, path);
|
let prop = getPropByPath(model, path);
|
||||||
|
|
||||||
if (Array.isArray(value) && value.length > 0) {
|
// if (Array.isArray(value) && value.length > 0) {
|
||||||
|
// this.validateDisabled = true;
|
||||||
|
// prop.o[prop.k] = [];
|
||||||
|
// } else if (value !== this.initialValue) {
|
||||||
|
// this.validateDisabled = true;
|
||||||
|
// prop.o[prop.k] = this.initialValue;
|
||||||
|
// }
|
||||||
|
if (Array.isArray(value)) {
|
||||||
this.validateDisabled = true;
|
this.validateDisabled = true;
|
||||||
prop.o[prop.k] = [];
|
prop.o[prop.k] = [].concat(this.initialValue);
|
||||||
} else if (value !== this.initialValue) {
|
} else {
|
||||||
this.validateDisabled = true;
|
this.validateDisabled = true;
|
||||||
prop.o[prop.k] = this.initialValue;
|
prop.o[prop.k] = this.initialValue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue