From a8d8754030660700f947db5965f99911e6c65507 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Wed, 31 Jan 2024 12:20:40 +0100 Subject: [PATCH] Update JS boolean evaluation helper --- src/js/utility.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/js/utility.js b/src/js/utility.js index d0c35e82..9c46d185 100644 --- a/src/js/utility.js +++ b/src/js/utility.js @@ -153,21 +153,36 @@ async function fcn_ajaxGet(data = {}, url = null, headers = {}) { */ function fcn_evaluateAsBoolean(candidate, fallback = false) { - // Is the candidate a boolean? - if (typeof candidate === 'boolean') { - return candidate; - } - // Does the candidate even exist? if (typeof candidate === 'undefined') { return fallback; } + // Is the candidate a boolean? + if (typeof candidate === 'boolean') { + return candidate; + } + // Is the candidate a checkbox? if (candidate instanceof HTMLInputElement && candidate.getAttribute('type') === 'checkbox') { return candidate.checked; } + // Is the candidate a label? (not currently used) + // if (candidate instanceof HTMLInputElement && candidate.getAttribute('type') === 'label') { + // const innerInput = candidate.querySelector('[type="checkbox"]'); + + // if (innerInput) { + // return innerInput.checked; + // } else if( candidate.getAttribute('for') ) { + // const forTarget = _$(`[type="checkbox"][name="${candidate.getAttribute('for')}"]`); + + // if (forTarget) { + // return forTarget.checked; + // } + // } + // } + // Is the candidate an element with (data-) value? if (candidate instanceof HTMLElement) { if (candidate.hasAttribute('value')) {