From b7d78dcb511e79ca140971d45b2ed68637d177e4 Mon Sep 17 00:00:00 2001 From: Rpgdudester <44619542+Rpgdudester@users.noreply.github.com> Date: Mon, 2 May 2022 13:43:54 -0500 Subject: [PATCH] Updated to allow for options disable Added in checks to see if option has disabled attribute, if they do, disable the option, otherwise, carry on. --- source/js/dselect.js | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/source/js/dselect.js b/source/js/dselect.js index 8b67424..cd14be4 100644 --- a/source/js/dselect.js +++ b/source/js/dselect.js @@ -156,21 +156,28 @@ function dselect(el, option = {}) { } function itemTags(options) { - let items = [] - for (const option of options) { - if (option.tagName === 'OPTGROUP') { - items.push(``) + let items = []; + for (const option2 of options) { + if (option2.tagName === "OPTGROUP") { + items.push(``); } else { - const hidden = isPlaceholder(option) ? ' hidden' : '' - const active = option.selected ? ' active' : '' - const disabled = el.multiple && option.selected ? ' disabled' : '' - const value = option.value - const text = option.textContent - items.push(`${text}`) + const hidden = isPlaceholder(option2) ? " hidden" : ""; + const active = option2.selected ? " active" : ""; + const disabled = option2.selected ? " disabled" : ""; + const disabledvalue = option2.getAttribute("disabled") + disableitem = ''; + if (disabledvalue !== null) { + disableitem = "disabled='true'"; + } else { + disableitem = ""; + } + const value = option2.value; + const text = option2.textContent; + items.push(`${text}`); } } - items = items.join('') - return items + items = items.join(""); + return items; } function createDom() { @@ -222,4 +229,4 @@ function dselect(el, option = {}) { } el.addEventListener('change', updateDom) -} \ No newline at end of file +}