소스 검색

Merge pull request #463 from baiyaaaaa/feat-form

fix reset method
杨奕 8 년 전
부모
커밋
3d18463415
2개의 변경된 파일16개의 추가작업 그리고 6개의 파일을 삭제
  1. 2 0
      CHANGELOG.md
  2. 14 6
      packages/form/src/form-item.vue

+ 2 - 0
CHANGELOG.md

@@ -4,6 +4,8 @@
 
 
 *2016-XX-XX*
 *2016-XX-XX*
 
 
+- 修复 Form reset method 对日期控件不起效的问题
+
 #### 非兼容性更新
 #### 非兼容性更新
 
 
 - 全屏 Loading 现在默认不再锁定屏幕滚动。如果需要的话,可添加 `lock` 修饰符
 - 全屏 Loading 现在默认不再锁定屏幕滚动。如果需要的话,可添加 `lock` 修饰符

+ 14 - 6
packages/form/src/form-item.vue

@@ -78,7 +78,8 @@
         validateDisabled: false,
         validateDisabled: false,
         validating: false,
         validating: false,
         validator: {},
         validator: {},
-        isRequired: false
+        isRequired: false,
+        initialValue: null
       };
       };
     },
     },
     methods: {
     methods: {
@@ -118,12 +119,9 @@
         if (Array.isArray(value) && value.length > 0) {
         if (Array.isArray(value) && value.length > 0) {
           this.validateDisabled = true;
           this.validateDisabled = true;
           model[this.prop] = [];
           model[this.prop] = [];
-        } else if (typeof value === 'string' && value !== '') {
+        } else if (value) {
           this.validateDisabled = true;
           this.validateDisabled = true;
-          model[this.prop] = '';
-        } else if (typeof value === 'number') {
-          this.validateDisabled = true;
-          model[this.prop] = 0;
+          model[this.prop] = this.initialValue;
         }
         }
       },
       },
       getRules() {
       getRules() {
@@ -151,12 +149,22 @@
         }
         }
 
 
         this.validate('change');
         this.validate('change');
+      },
+      getInitialValue() {
+        var value = this.form.model[this.prop];
+        if (value === undefined) {
+          return value;
+        } else {
+          return JSON.parse(JSON.stringify(value));
+        }
       }
       }
     },
     },
     mounted() {
     mounted() {
       if (this.prop) {
       if (this.prop) {
         this.dispatch('form', 'el.form.addField', [this]);
         this.dispatch('form', 'el.form.addField', [this]);
 
 
+        this.initialValue = this.getInitialValue();
+
         let rules = this.getRules();
         let rules = this.getRules();
 
 
         if (rules.length) {
         if (rules.length) {