Skip to content

Commit 0ed8d18

Browse files
wacky6ziyoung
authored andcommitted
Select: fix form change validation (#11672)
1 parent 1f24f2a commit 0ed8d18

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

packages/select/src/select.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@
339339
this.cachedPlaceHolder = this.currentPlaceholder = val;
340340
},
341341
342-
value(val) {
342+
value(val, oldVal) {
343343
if (this.multiple) {
344344
this.resetInputHeight();
345345
if (val.length > 0 || (this.$refs.input && this.query !== '')) {
@@ -356,6 +356,9 @@
356356
if (this.filterable && !this.multiple) {
357357
this.inputLength = 20;
358358
}
359+
if (!valueEquals(val, oldVal)) {
360+
this.dispatch('ElFormItem', 'el.form.change', val);
361+
}
359362
},
360363
361364
visible(val) {
@@ -503,7 +506,6 @@
503506
emitChange(val) {
504507
if (!valueEquals(this.value, val)) {
505508
this.$emit('change', val);
506-
this.dispatch('ElFormItem', 'el.form.change', val);
507509
}
508510
},
509511

test/unit/specs/form.spec.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,19 @@ describe('Form', () => {
380380
expect(valid).to.false;
381381
setTimeout(_ => {
382382
expect(field.validateMessage).to.equal('请选择活动区域');
383-
// programatic modification of bound value does not triggers change validation
383+
// programatic modification triggers change validation
384384
vm.form.region = 'shanghai';
385385
setTimeout(_ => {
386-
expect(field.validateMessage).to.equal('请选择活动区域');
387-
// user modification of bound value triggers change validation
388-
vm.$refs.opt.$el.click();
386+
expect(field.validateMessage).to.equal('');
387+
vm.form.region = '';
389388
setTimeout(_ => {
390-
expect(field.validateMessage).to.equal('');
391-
done();
389+
expect(field.validateMessage).to.equal('请选择活动区域');
390+
// user modification of bound value triggers change validation
391+
vm.$refs.opt.$el.click();
392+
setTimeout(_ => {
393+
expect(field.validateMessage).to.equal('');
394+
done();
395+
}, 100);
392396
}, 100);
393397
}, 100);
394398
}, 100);

0 commit comments

Comments
 (0)