Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date-picker: fix form change validation #12328

Merged
merged 1 commit into from Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/date-picker/src/picker.vue
Expand Up @@ -428,6 +428,11 @@ export default {
if (this.picker) {
this.picker.defaultValue = val;
}
},
value(val, oldVal) {
if (!valueEquals(val, oldVal)) {
this.dispatch('ElFormItem', 'el.form.change', val);
}
}
},

Expand Down Expand Up @@ -894,7 +899,6 @@ export default {
// determine user real change only
if (!valueEquals(val, this.valueOnOpen)) {
this.$emit('change', val);
this.dispatch('ElFormItem', 'el.form.change', val);
this.valueOnOpen = val;
}
},
Expand Down
8 changes: 4 additions & 4 deletions test/unit/specs/form.spec.js
Expand Up @@ -483,11 +483,11 @@ describe('Form', () => {
expect(valid).to.not.true;
setTimeout(_ => {
expect(field.validateMessage).to.equal('请选择日期');
// programatic modification does not trigger change
vm.value = new Date();
// programatic modification triggers change validation
vm.form.date = new Date();
setTimeout(_ => {
expect(field.validateMessage).to.equal('请选择日期');
vm.value = '';
expect(field.validateMessage).to.equal('');
vm.form.date = '';
// user modification triggers change
const input = vm.$refs.picker.$el.querySelector('input');
input.blur();
Expand Down