DatePicker: nuke invalid input on close (#10749)

pull/10434/merge
Jiewei Qian 2018-04-17 16:15:47 +10:00 committed by 杨奕
parent 1f4adb7c08
commit d8f861e929
2 changed files with 28 additions and 6 deletions

View File

@ -390,12 +390,7 @@ export default {
} else {
this.hidePicker();
this.emitChange(this.value);
// flush user input if it is parsable
// this.displayValue here is not a typo, it merges text for both panels in range mode
const parsedValue = this.parseString(this.displayValue);
if (this.userInput && parsedValue && this.isValidValue(parsedValue)) {
this.userInput = null;
}
this.dispatch('ElFormItem', 'el.form.blur');
this.$emit('blur', this);
this.blur();

View File

@ -261,6 +261,33 @@ describe('DatePicker', () => {
}, DELAY);
});
it('nuke invalid input on close', done => {
vm = createVue({
template: '<el-date-picker v-model="value" value-format="yyyy-MM-dd" ref="compo" />',
data() {
return {
value: '2010-10-01'
};
}
}, true);
const compo = vm.$refs.compo;
const input = compo.$el.querySelector('input');
input.blur();
input.focus();
setTimeout(_ => {
compo.userInput = 'abc';
compo.handleChange(); // simplified test
compo.handleClose();
setTimeout(_ => {
expect(input.value).to.equal('2010-10-01');
expect(vm.value).to.equal('2010-10-01');
done();
}, DELAY);
}, DELAY);
});
it('select datetime with defaultTime', done => {
vm = createVue({
template: `