From 38646a11711eebb4837bb8a5b37c585efd020b35 Mon Sep 17 00:00:00 2001 From: 梁灏 Date: Tue, 14 Feb 2017 10:51:12 +0800 Subject: [PATCH] fixed Form reset using Input or Switch --- src/components/form/form-item.vue | 2 +- test/routers/form.vue | 45 +++++++++++++++++++++++---------------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/components/form/form-item.vue b/src/components/form/form-item.vue index 20771f8..bb44f6f 100644 --- a/src/components/form/form-item.vue +++ b/src/components/form/form-item.vue @@ -189,7 +189,7 @@ if (Array.isArray(value) && value.length > 0) { this.validateDisabled = true; prop.o[prop.k] = []; - } else if (value) { + } else if (value !== this.initialValue) { this.validateDisabled = true; prop.o[prop.k] = this.initialValue; } diff --git a/test/routers/form.vue b/test/routers/form.vue index 85b28f4..ba1484e 100644 --- a/test/routers/form.vue +++ b/test/routers/form.vue @@ -1,17 +1,21 @@ @@ -19,23 +23,17 @@ export default { data () { return { - formInline: { - user: '', - password: '' + formValidate: { + input: '123', + ajax: true }, - ruleInline: { - user: [ - { required: true, message: '请填写用户名', trigger: 'change' } - ], - password: [ - { required: true, message: '请填写密码', trigger: 'blur' }, - { type: 'string', min: 6, message: '密码长度不能小于6位', trigger: 'change' } - ] + ruleValidate: { + } } }, methods: { - handleSubmit(name) { + handleSubmit (name) { this.$refs[name].validate((valid) => { if (valid) { this.$Message.success('提交成功!'); @@ -43,6 +41,9 @@ this.$Message.error('表单验证失败!'); } }) + }, + handleReset (name) { + this.$refs[name].resetFields(); } } } -- libgit2 0.21.4