Skip to content

Commit

Permalink
Select: fix allowCreate bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Leopoldthecoder committed Jan 3, 2017
1 parent ead1d1d commit 68c1c84
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/select/src/option.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
},
Expand Down
19 changes: 18 additions & 1 deletion packages/select/src/select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -191,6 +192,8 @@
return {
options: [],
cachedOptions: [],
createdOption: null,
createdSelected: false,
selected: this.multiple ? [] : {},
isSelect: true,
inputLength: 20,
Expand Down Expand Up @@ -276,7 +279,12 @@
if (!this.multiple) {
this.getOverflows();
if (this.selected) {
this.selectedLabel = this.selected.currentLabel;
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;
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -382,6 +396,9 @@
});
}
this.selected = result;
this.$nextTick(() => {
this.resetInputHeight();
});
},
handleIconClick(event) {
Expand Down

0 comments on commit 68c1c84

Please sign in to comment.