Skip to content
Snippets Groups Projects
Verified Commit 11a314a2 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

feat: new flag feature.useStrictValueComparison #206

parent cdf7f460
No related branches found
No related tags found
No related merge requests found
...@@ -435,6 +435,7 @@ class Select extends CustomControl { ...@@ -435,6 +435,7 @@ class Select extends CustomControl {
* @property {Boolean} features.closeOnSelect=false Close the dropdown when an option is selected (since 3.54.0) * @property {Boolean} features.closeOnSelect=false Close the dropdown when an option is selected (since 3.54.0)
* @property {Boolean} features.emptyValueIfNoOptions=false If no options are available, the selection is set to an empty array * @property {Boolean} features.emptyValueIfNoOptions=false If no options are available, the selection is set to an empty array
* @property {Boolean} features.storeFetchedData=false Store fetched data in the object * @property {Boolean} features.storeFetchedData=false Store fetched data in the object
* @property {Boolean} features.useStrictValueComparison=true Use strict value comparison for the selection
* @property {Boolean} filter.defaultValue=* Default filter value, if the filter is empty * @property {Boolean} filter.defaultValue=* Default filter value, if the filter is empty
* @property {Boolean} filter.mode=options Filter mode, values: options, remote, disabled * @property {Boolean} filter.mode=options Filter mode, values: options, remote, disabled
* @property {Object} templates Template definitions * @property {Object} templates Template definitions
...@@ -471,6 +472,7 @@ class Select extends CustomControl { ...@@ -471,6 +472,7 @@ class Select extends CustomControl {
closeOnSelect: false, closeOnSelect: false,
emptyValueIfNoOptions: false, emptyValueIfNoOptions: false,
storeFetchedData: false, storeFetchedData: false,
useStrictValueComparison: false,
}, },
url: null, url: null,
labels: { labels: {
...@@ -566,7 +568,6 @@ class Select extends CustomControl { ...@@ -566,7 +568,6 @@ class Select extends CustomControl {
let lastValue = self.value; let lastValue = self.value;
self[internalSymbol].attachObserver( self[internalSymbol].attachObserver(
new Observer(function () { new Observer(function () {
if (isObject(this) && this instanceof ProxyObserver) { if (isObject(this) && this instanceof ProxyObserver) {
const n = this.getSubject()?.options?.value; const n = this.getSubject()?.options?.value;
...@@ -683,6 +684,8 @@ class Select extends CustomControl { ...@@ -683,6 +684,8 @@ class Select extends CustomControl {
new Processing(10, () => { new Processing(10, () => {
this.setOption("options", []);
fetchData fetchData
.call(this, url) .call(this, url)
.then((map) => { .then((map) => {
...@@ -693,14 +696,27 @@ class Select extends CustomControl { ...@@ -693,14 +696,27 @@ class Select extends CustomControl {
map instanceof Set || map instanceof Set ||
map instanceof Map map instanceof Map
) { ) {
this.importOptions(map); this.importOptions(map);
this[lastFetchedDataSymbol] = map; this[lastFetchedDataSymbol] = map;
let result;
const selection = this.getOption("selection")
if (selection) {
result = setSelection.call(this, selection);
} else if (this.hasAttribute("value")) {
result = setSelection.call(this, this.getAttribute("value"));
} else {
result = setSelection.call(this, []);
}
setTimeout(() => { setTimeout(() => {
setStatusOrRemoveBadges.call(this, "closed"); setStatusOrRemoveBadges.call(this, "closed");
resolve(); resolve();
}, 10); }, 10);
return;
return result;
} }
setStatusOrRemoveBadges.call(this, "error"); setStatusOrRemoveBadges.call(this, "error");
...@@ -1022,11 +1038,31 @@ function buildSelectionLabel(value) { ...@@ -1022,11 +1038,31 @@ function buildSelectionLabel(value) {
const options = this.getOption("options"); const options = this.getOption("options");
for (let i = 0; i < options.length; i++) { for (let i = 0; i < options.length; i++) {
const o = options?.[i]; let o = options?.[i];
if (isObject(o) && o?.["value"] === value) { let l, v, v2;
return o?.["label"];
} else if (isPrimitive(o) && o === value) { if (this.getOption("features.useStrictValueComparison") === true) {
v = value;
} else {
v = `${value}`;
}
if (isPrimitive(o) && o === value) {
return o; return o;
} else if (!isObject(o)) {
continue;
}
if (this.getOption("features.useStrictValueComparison") === true) {
l = o?.["label"]
v2 = o?.["value"]
} else {
l = `${o?.["label"]}`;
v2 = `${o?.["value"]}`;
}
if (v2 === v) {
return l;
} }
} }
...@@ -1526,8 +1562,13 @@ function handleOptionKeyboardEvents(event) { ...@@ -1526,8 +1562,13 @@ function handleOptionKeyboardEvents(event) {
case "Space": case "Space":
const path = event.composedPath(); const path = event.composedPath();
const element = path?.[0]; const element = path?.[0];
if (element instanceof HTMLElement) {
fireEvent(element.getElementsByTagName("input"), "click"); const input = element.getElementsByTagName("input")
if (!input) {
return;
}
fireEvent(input, "click");
}
event.preventDefault(); event.preventDefault();
break; break;
...@@ -1672,6 +1713,7 @@ function focusFilter(focusOptions) { ...@@ -1672,6 +1713,7 @@ function focusFilter(focusOptions) {
* @throws {Error} unsupported type * @throws {Error} unsupported type
*/ */
function gatherState() { function gatherState() {
const type = this.getOption("type"); const type = this.getOption("type");
if (["radio", "checkbox"].indexOf(type) === -1) { if (["radio", "checkbox"].indexOf(type) === -1) {
throw new Error("unsupported type"); throw new Error("unsupported type");
...@@ -1936,6 +1978,7 @@ function convertSelectionToValue(selection) { ...@@ -1936,6 +1978,7 @@ function convertSelectionToValue(selection) {
* @throws {Error} no shadow-root is defined * @throws {Error} no shadow-root is defined
*/ */
function setSelection(selection) { function setSelection(selection) {
if (isString(selection)) { if (isString(selection)) {
const result = convertValueToSelection.call(this, selection); const result = convertValueToSelection.call(this, selection);
selection = result?.selection; selection = result?.selection;
...@@ -2073,31 +2116,11 @@ function show() { ...@@ -2073,31 +2116,11 @@ function show() {
new Processing(200, () => { new Processing(200, () => {
this.fetch() this.fetch()
.then(() => {
setTimeout(() => {
let result;
if (this.hasAttribute("value")) {
result = setSelection.call(this, this.getAttribute("value"));
} else {
result = setSelection.call(this, []);
}
result
.then(() => {
show.call(this);
})
.catch((e) => {
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, `${e}`);
});
}, 100);
})
.catch((e) => { .catch((e) => {
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message); addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
setStatusOrRemoveBadges.call(this, "error"); setStatusOrRemoveBadges.call(this, "error");
}); });
}) }).run().catch((e) => {
.run()
.catch((e) => {
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message); addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment