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