From af70fedbe45537312b39477cd56e175d5ece951b Mon Sep 17 00:00:00 2001 From: Sanae Date: Thu, 23 May 2024 23:00:28 +0000 Subject: [PATCH] inner elements for custom select options, update metadata addedit --- html/media/metadata_addedit.html | 26 +++++++++++++------------- ui/fields/select.js | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/html/media/metadata_addedit.html b/html/media/metadata_addedit.html index 1d0e1f78..fac9220a 100644 --- a/html/media/metadata_addedit.html +++ b/html/media/metadata_addedit.html @@ -18,14 +18,14 @@
- + + Text (single line) + Text (multiple lines) + Number (integer) + Yes/No + Drop-Down Selection + Tags +
@@ -40,11 +40,11 @@
- + + Required + Optional + Hidden +
diff --git a/ui/fields/select.js b/ui/fields/select.js index 599f2938..b4edfe72 100644 --- a/ui/fields/select.js +++ b/ui/fields/select.js @@ -322,6 +322,8 @@ class OBFieldSelect extends OBField { renderEdit() { // get options from data-options and json decode if (!this.#options) this.#options = JSON.parse(this.getAttribute('data-options')); + if (!this.#options) this.#options = this.#loadInnerOptions(); + if (!this.popular) this.popular = JSON.parse(this.getAttribute('data-popular')); if (!this.selected) this.selected = JSON.parse(this.getAttribute('data-value')); this.multiple = this.hasAttribute('data-multiple'); @@ -363,6 +365,27 @@ class OBFieldSelect extends OBField { this.updateSelected(); } + #loadInnerOptions() { + var options = {}; + + for (const child of this.children) { + if (child.tagName === 'OB-OPTION') { + let key = child.getAttribute('value'); + if (key) { + options[key] = child.innerHTML; + } else { + // If you mix items that have a value attribute and items without them, and also + // some of the values are numbers lower than the length of the iterated options up + // to this point, they'll get overwritten, so this causes problems. But also come + // on now. + options[Object.keys(options).length] = child.innerHTML; + } + } + } + + return options; + } + } customElements.define('ob-field-select', OBFieldSelect); \ No newline at end of file