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