diff --git a/front/core/components/drop-down/index.js b/front/core/components/drop-down/index.js index 9f2dfe424..ed7de7179 100644 --- a/front/core/components/drop-down/index.js +++ b/front/core/components/drop-down/index.js @@ -29,13 +29,16 @@ export default class DropDown extends Popover { } set search(value) { - let oldValue = this._search; + function nullify(value) { + return value == '' || value == undefined ? null : value; + } + + let oldValue = nullify(this._search); this._search = value; if (!this.shown) return; - value = value == '' || value == null ? null : value; - oldValue = oldValue == '' || oldValue == null ? null : oldValue; + value = nullify(value); if (value === oldValue && this.modelData != null) return; if (value != null) @@ -45,7 +48,8 @@ export default class DropDown extends Popover { if (this.model) { this.model.clear(); - if (!this.data) { + + if (this.model instanceof CrudModel) { this.searchTimeout = this.$timeout(() => { this.refreshModel(); this.searchTimeout = null; @@ -353,6 +357,7 @@ export default class DropDown extends Popover { set model(value) { this.linkEvents({_model: value}, {dataChange: this.onDataChange}); this.onDataChange(); + this.search = this.search; } get url() { @@ -362,10 +367,9 @@ export default class DropDown extends Popover { set url(value) { this._url = value; if (value) { - this.model = new CrudModel(this.$q, this.$http); - this.model.autoLoad = false; - this.model.url = value; - this.model.$onInit(); + let model = new CrudModel(this.$q, this.$http); + model.url = value; + this.initModel(model); } } @@ -376,13 +380,18 @@ export default class DropDown extends Popover { set data(value) { this._data = value; if (value) { - this.model = new ArrayModel(this.$q, this.$filter); - this.model.autoLoad = false; - this.model.orgData = value; - this.model.$onInit(); + let model = new ArrayModel(this.$q, this.$filter); + model.orgData = value; + this.initModel(model); } } + initModel(model) { + model.autoLoad = false; + model.$onInit(); + this.model = model; + } + refreshModel() { let model = this.model;