From b35dc87db6d05e514ac787c19dda1e279e741b12 Mon Sep 17 00:00:00 2001 From: Felix Hamann Date: Sat, 20 Apr 2019 22:24:50 +0200 Subject: [PATCH] make target for interactive-fieldset optional --- static/js/utils/form.js | 13 +++---------- templates/widgets/aform/aform.hamlet | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/static/js/utils/form.js b/static/js/utils/form.js index b2a449e2a..ad87b3501 100644 --- a/static/js/utils/form.js +++ b/static/js/utils/form.js @@ -182,15 +182,8 @@ } conditionalValue = element.dataset.conditionalValue; - if (element.matches(INTERACTIVE_FIELDSET_UTIL_TARGET_SELECTOR)) { - target = element; - } - if (!target) { - target = element.closest(INTERACTIVE_FIELDSET_UTIL_TARGET_SELECTOR); - } - if (!target) { - throw new Error('Interactive Fieldset needs to be a target or have a target-ancestor!'); - } + // check if there is a target ancestor, otherwise target the fieldset itself + target = element.closest(INTERACTIVE_FIELDSET_UTIL_TARGET_SELECTOR) || element; childInputs = Array.from(element.querySelectorAll(INTERACTIVE_FIELDSET_CHILD_SELECTOR)); @@ -212,7 +205,7 @@ function updateVisibility() { var active = matchesConditionalValue(); - + target.classList.toggle('hidden', !active); childInputs.forEach(function(el) { diff --git a/templates/widgets/aform/aform.hamlet b/templates/widgets/aform/aform.hamlet index 00f8755f2..91ebc2b93 100644 --- a/templates/widgets/aform/aform.hamlet +++ b/templates/widgets/aform/aform.hamlet @@ -11,7 +11,7 @@ $case formLayout

^{fvLabel view} $else -
+
$if not (Blaze.null $ fvLabel view)