(function (document) { "use strict"; // Wait for jQuery to be available function init() { var $ = Granite.$; if (typeof $ === 'undefined' || typeof $.fn === 'undefined') { setTimeout(init, 100); return; } $(document).on("foundation-contentloaded", function (e) { Coral.commons.ready(function () { showHideHandler($(".cq-dialog-dropdown-showhide", e.target)); }); }); // Handle create wizard events $(document).on("coral-overlay:open foundation-wizard-stepchange", function () { setTimeout(function() { Coral.commons.ready(function () { showHideHandler($(".cq-dialog-dropdown-showhide")); }); }, 300); }); // Handle dropdown changes $(document).on("change coral-select:change", ".cq-dialog-dropdown-showhide", function () { showHideHandler($(this)); }); // Handle changes in multifield $(document).on("change", ".cq-dialog-dropdown-showhide", function () { if ($(this).closest('.coral3-Multifield').length > 0) { showHideHandler($(this)); } }); function showHideHandler(el) { el.each(function () { var element = this; if ($(element).is("coral-select")) { Coral.commons.ready(element, function (component) { multiSelectShowHide(element); component.off("change.showhide"); component.on("change.showhide", function () { multiSelectShowHide(element); }); }); } }); } function multiSelectShowHide(element) { let target = $(element).data("cqDialogDropdownShowhideTarget"); if (!target) return; // Find targets in context (works for both dialog and wizard) let $container = $(element).closest('.cq-dialog-content-page, coral-dialog-content, .foundation-wizard-content'); let $target = $container.find(target); if ($target.length === 0) { $target = $(target); } if ($target.length > 0) { // Get selected values let selectedValues = []; if (element.values && element.values.length > 0) { selectedValues = element.values; } else if (element.value) { selectedValues = [element.value]; } else if (element.selectedItem && element.selectedItem.value) { selectedValues = [element.selectedItem.value]; } // Show/hide targets based on their data attribute $target.each(function () { let $this = $(this); let targetValueList = $this.data('showhidetargetvalue'); if (typeof targetValueList !== "undefined") { let shouldShow = false; let targetValues = targetValueList.toString().replace(/ /g, '').split(','); targetValues.forEach(function(targetValue) { if (selectedValues.indexOf(targetValue) !== -1) { shouldShow = true; } }); if (shouldShow) { $this.removeClass('hide'); } else { $this.addClass('hide'); } } }); } } } // Start initialization init(); })(document); (function (document) { "use strict"; // Wait for jQuery to be available function init() { var $ = Granite.$; if (typeof $ === 'undefined' || typeof $.fn === 'undefined') { setTimeout(init, 100); return; } // When dialog gets injected $(document).on("foundation-contentloaded", function (e) { // If there is already an initial value make sure the target element visibility is correct checkboxInvertedShowHideHandler($(".cq-dialog-checkbox-showhide-inverted", e.target)); }); $(document).on("change", ".cq-dialog-checkbox-showhide-inverted", function (e) { checkboxInvertedShowHideHandler($(this)); }); function checkboxInvertedShowHideHandler(el) { el.each(function (i, element) { if($(element).is("coral-checkbox")) { // Handle Coral3 checkbox Coral.commons.ready(element, function (component) { showHideInverted(component, element); component.on("change", function () { showHideInverted(component, element); }); }); } else { // Handle Coral2 checkbox var component = $(element).data("checkbox"); if (component) { showHideInverted(component, element); } } }) } function showHideInverted(component, element) { // Get the selector to find the target elements from data attribute var target = $(element).data("cqDialogCheckboxShowhideTarget"); if (!target) { return; } // Find targets in context (works for both dialog and wizard, searches across tabs) var $container = $(element).closest('.cq-dialog-content-page, coral-dialog-content, .foundation-wizard-content'); var $target = $container.find(target); if ($target.length === 0) { $target = $(target); } if ($target.length > 0) { $target.each(function() { var $field = $(this); // Find the parent field wrapper to hide label + field together var $fieldWrapper = $field.closest('.coral-Form-fieldwrapper'); // INVERTED LOGIC: checked = hide, unchecked = show if (component.checked) { $field.addClass("hide"); if ($fieldWrapper.length > 0) { $fieldWrapper.addClass("hide"); } } else { $field.removeClass("hide"); if ($fieldWrapper.length > 0) { $fieldWrapper.removeClass("hide"); } } }); } } } // Start initialization init(); })(document);