DEV: better detection of new item (#8889)

This commit is contained in:
Joffrey JAFFEUX 2020-02-07 14:12:17 +01:00 committed by GitHub
parent a0bf2ac313
commit 252989e261
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 7 deletions

View File

@ -87,6 +87,7 @@ export default Component.extend(
hasNoContent: true,
highlighted: null,
noneItem: null,
newItem: null,
filter: null,
modifyContent: bind(this, this._modifyContentWrapper),
@ -224,7 +225,8 @@ export default Component.extend(
this.selectKit.setProperties({
hasSelection: !isEmpty(this.value),
noneItem: this._modifyNoSelectionWrapper()
noneItem: this._modifyNoSelectionWrapper(),
newItem: null
});
if (this.selectKit.isExpanded) {
@ -563,7 +565,6 @@ export default Component.extend(
}
const noneItem = this.selectKit.noneItem;
if (
this.selectKit.options.allowAny &&
filter &&
@ -571,7 +572,8 @@ export default Component.extend(
) {
filter = this.createContentFromInput(filter);
if (this.validateCreate(filter, content)) {
content.unshift(this.defaultItem(filter, filter));
this.selectKit.set("newItem", this.defaultItem(filter, filter));
content.unshift(this.selectKit.newItem);
}
}
@ -590,7 +592,7 @@ export default Component.extend(
this.selectKit.setProperties({
highlighted:
this.singleSelect && this.value
? this.itemForValue(this.value)
? this.itemForValue(this.value, this.mainCollection)
: this.mainCollection.firstObject,
isLoading: false,
hasNoContent

View File

@ -47,7 +47,8 @@ export default Component.extend(UtilsMixin, {
if (
this.selectKit.options.allowAny &&
this.rowValue === this.selectKit.filter &&
this.getName(this.selectKit.noneItem) !== this.rowName
this.getName(this.selectKit.noneItem) !== this.rowName &&
this.getName(this.selectKit.newItem) === this.rowName
) {
return I18n.t("select_kit.create", { content: label });
}

View File

@ -13,9 +13,9 @@ export default Mixin.create({
}
},
itemForValue(value) {
itemForValue(value, content) {
if (this.selectKit.valueProperty) {
return this.mainCollection.findBy(this.selectKit.valueProperty, value);
return content.findBy(this.selectKit.valueProperty, value);
} else {
return value;
}