diff --git a/source/components/form/select.mjs b/source/components/form/select.mjs index 5ecf9cff216daee2312570535ba34725c5eb0c23..50e56e2d3c6e43f1ba6382661703a344cd89b2f4 100644 --- a/source/components/form/select.mjs +++ b/source/components/form/select.mjs @@ -221,6 +221,12 @@ const areOptionsAvailableAndInitSymbol = Symbol("@@areOptionsAvailableAndInit"); */ const disabledRequestMarker = Symbol("@@disabledRequestMarker"); +/** + * @private + * @type {symbol} + */ +const runLookupOnceSymbol = Symbol("runLookupOnce"); + /** * @private * @type {number} @@ -560,7 +566,7 @@ class Select extends CustomControl { ); areOptionsAvailableAndInit.call(self); - },0); + }, 0); return this; } @@ -1120,14 +1126,14 @@ function attachResizeObserver() { }); - let parent = this.parentNode; - while (!(parent instanceof HTMLElement) && parent !== null) { - parent = parent.parentNode; - } + let parent = this.parentNode; + while (!(parent instanceof HTMLElement) && parent !== null) { + parent = parent.parentNode; + } - if (parent instanceof HTMLElement) { - this[resizeObserverSymbol].observe(parent); - } + if (parent instanceof HTMLElement) { + this[resizeObserverSymbol].observe(parent); + } } @@ -1352,13 +1358,13 @@ function initOptionObserver() { self.updateI18n(); } catch (e) { addErrorAttribute(self, e); - setStatusOrRemoveBadges.call(self, "error"); + setStatusOrRemoveBadges.call(self, "error"); } try { areOptionsAvailableAndInit.call(self); } catch (e) { addErrorAttribute(self, e); - setStatusOrRemoveBadges.call(self, "error"); + setStatusOrRemoveBadges.call(self, "error"); } setSummaryAndControlText.call(self); @@ -2246,8 +2252,8 @@ function isValueIsEmpty(value) { let equivalents = this.getOption("empty.equivalents"); if (!isArray(equivalents)) { if (equivalents === undefined) { - return false; - } + return false; + } equivalents = [equivalents]; } @@ -2262,13 +2268,13 @@ function isValueIsEmpty(value) { */ function isValueIsEmptyThenGetNormalize(value) { let emptyDefault = null - if (this.getOption("type")==="checkbox") { + if (this.getOption("type") === "checkbox") { emptyDefault = this.getOption("empty.defaultValueCheckbox"); } else { emptyDefault = this.getOption("empty.defaultValueRadio"); } - if (isValueIsEmpty.call(this,value)) { + if (isValueIsEmpty.call(this, value)) { return emptyDefault; } @@ -2289,13 +2295,13 @@ function setSelection(selection) { selection = result?.selection; } - selection = isValueIsEmptyThenGetNormalize.call(this,selection); + selection = isValueIsEmptyThenGetNormalize.call(this, selection); validateArray(selection); let resultSelection = []; for (let i = 0; i < selection.length; i++) { - if(isValueIsEmpty.call(this,selection[i].value)) { + if (isValueIsEmpty.call(this, selection[i].value)) { continue } @@ -2329,12 +2335,16 @@ function setSelection(selection) { fireEvent(this, "change"); // https://gitlab.schukai.com/oss/libraries/javascript/monster/-/issues/291 - const lazyLoadFlag = - this.getOption("features.lazyLoad") && this[lazyLoadDoneSymbol] !== true; - let remoteFilterFlag = getFilterMode.call(this) === FILTER_MODE_REMOTE; + if(this[runLookupOnceSymbol] !== true && selection.length > 0) { + + this[runLookupOnceSymbol] = true - if (lazyLoadFlag || remoteFilterFlag) { - lookupSelection.call(self); + const lazyLoadFlag = + this.getOption("features.lazyLoad") && this[lazyLoadDoneSymbol] !== true; + let remoteFilterFlag = getFilterMode.call(this) === FILTER_MODE_REMOTE; + if (lazyLoadFlag || remoteFilterFlag) { + lookupSelection.call(self); + } } return new Processing(() => { @@ -2863,12 +2873,12 @@ function getTemplate() { data-monster-attributes=" type path:type, role path:role, - value path:options | index:value, + value path:options.value, name path:name, part path:type | prefix:option- | suffix: form, class path:options.class " tabindex="-1"> - <div data-monster-replace="path:options | index:label" + <div data-monster-replace="path:options.label" part="option-label"></div> </label> </div>