make target for interactive-fieldset optional

This commit is contained in:
Felix Hamann 2019-04-20 22:24:50 +02:00
parent 721630f4b2
commit b35dc87db6
2 changed files with 4 additions and 11 deletions

View File

@ -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) {

View File

@ -11,7 +11,7 @@ $case formLayout
<h3 .form-section-title>
^{fvLabel view}
$else
<div .form-group .interactive-fieldset--target :fvRequired view:.form-group--required :not $ fvRequired view:.form-group--optional :isJust $ fvErrors view:.form-group--has-error>
<div .form-group :fvRequired view:.form-group--required :not $ fvRequired view:.form-group--optional :isJust $ fvErrors view:.form-group--has-error>
$if not (Blaze.null $ fvLabel view)
<label .form-group-label for=#{fvId view}>
<span .form-group-label__caption>