Merge pull request #2186 from Leopoldthecoder/select-fix

Select: fix allowCreate bug
pull/2199/head
baiyaaaaa 2017-01-04 16:30:48 +08:00 committed by GitHub
commit 9773276fee
2 changed files with 20 additions and 3 deletions

View File

@ -88,10 +88,10 @@
watch: {
currentLabel() {
this.dispatch('ElSelect', 'setSelected');
if (!this.created) this.dispatch('ElSelect', 'setSelected');
},
value() {
this.dispatch('ElSelect', 'setSelected');
if (!this.created) this.dispatch('ElSelect', 'setSelected');
}
},

View File

@ -98,6 +98,7 @@
import { addClass, removeClass, hasClass } from 'element-ui/src/utils/dom';
import { addResizeListener, removeResizeListener } from 'element-ui/src/utils/resize-event';
import { t } from 'element-ui/src/locale';
import merge from 'element-ui/src/utils/merge';
const sizeMap = {
'large': 42,
'small': 30,
@ -191,6 +192,8 @@
return {
options: [],
cachedOptions: [],
createdOption: null,
createdSelected: false,
selected: this.multiple ? [] : {},
isSelect: true,
inputLength: 20,
@ -276,7 +279,12 @@
if (!this.multiple) {
this.getOverflows();
if (this.selected) {
if (this.filterable && this.allowCreate &&
this.createdSelected && this.createdOption) {
this.selectedLabel = this.createdOption.currentLabel;
} else {
this.selectedLabel = this.selected.currentLabel;
}
if (this.filterable) this.query = this.selectedLabel;
}
}
@ -371,6 +379,12 @@
setSelected() {
if (!this.multiple) {
let option = this.getOption(this.value);
if (option.created) {
this.createdOption = merge({}, option);
this.createdSelected = true;
} else {
this.createdSelected = false;
}
this.selectedLabel = option.currentLabel;
this.selected = option;
return;
@ -382,6 +396,9 @@
});
}
this.selected = result;
this.$nextTick(() => {
this.resetInputHeight();
});
},
handleIconClick(event) {