Skip to content

Commit c6a5a3d

Browse files
committed
date-picker: fix form change validation
1 parent 250e3f6 commit c6a5a3d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

packages/date-picker/src/picker.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,11 @@ export default {
428428
if (this.picker) {
429429
this.picker.defaultValue = val;
430430
}
431+
},
432+
value(val, oldVal) {
433+
if (!valueEquals(val, oldVal)) {
434+
this.dispatch('ElFormItem', 'el.form.change', val);
435+
}
431436
}
432437
},
433438
@@ -894,7 +899,6 @@ export default {
894899
// determine user real change only
895900
if (!valueEquals(val, this.valueOnOpen)) {
896901
this.$emit('change', val);
897-
this.dispatch('ElFormItem', 'el.form.change', val);
898902
this.valueOnOpen = val;
899903
}
900904
},

test/unit/specs/form.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,11 @@ describe('Form', () => {
483483
expect(valid).to.not.true;
484484
setTimeout(_ => {
485485
expect(field.validateMessage).to.equal('请选择日期');
486-
// programatic modification does not trigger change
487-
vm.value = new Date();
486+
// programatic modification triggers change validation
487+
vm.form.date = new Date();
488488
setTimeout(_ => {
489-
expect(field.validateMessage).to.equal('请选择日期');
490-
vm.value = '';
489+
expect(field.validateMessage).to.equal('');
490+
vm.form.date = '';
491491
// user modification triggers change
492492
const input = vm.$refs.picker.$el.querySelector('input');
493493
input.blur();

0 commit comments

Comments
 (0)