在AEM 6.1(granite.ui)TouchUI对话框中有条件地启用/禁用字段

时间:2015-07-27 04:59:02

标签: adobe cq5 aem

有没有人根据AEM6.1 TouchUI对话框中前一个字段的值有条件禁用字段的经验?

为了给出一些上下文,我的TouchUI对话框中有一个复选框,用于启用/禁用(隐藏/显示)组件中的“调用操作”按钮。我想在对话框中禁用CTA buttonText和href字段,其中作者通过复选框禁用了CTA。相反,我想启用这些字段,其中选中CTA复选框以启用CTA。

我已经调查了/libs/cq/gui/components/authoring/dialog/dropdownshowhide/clientlibs/dropdownshowhide.js但它并不适合用途,因为这是专为隐藏或显示基于下拉列表值的字段而设计的并且我试图修改它以允许在复选框上使用类似的功能性并不富有成效。我想启用/禁用字段而不是隐藏显示它们。

1 个答案:

答案 0 :(得分:1)

经过一段时间的麻烦,我得到了这个工作,将class =“cq-dialog-checkbox-enabledisable”添加到我的吊索:resourceType =“granite / ui / components / foundation / form / checkbox”and class =“cq -dialog-checkbox-enabledisable-target“to sling:resourceType =”granite / ui / components / foundation / form / textarea“我想在我的cq:dialog.xml中禁用。

然后我创建了自己的clientLib,它依赖于granite.jquery和类别cq.authoring.dialog。

更新:事实证明,无法在顶层的路径浏览器字段类型上以编程方式设置disabled属性,因此您需要禁用其中包含的子字段(js-coral-pathbrowser-input和js-coral-pathbrowser)下面的代码片段已更新,以反映这一点。

  

  /**
 * Extension to the standard checkbox component. It enables/disables  other components based on the
 * selection made in the checkbox.
 *
 * How to use:
 *
 * - add the class cq-dialog-checkbox-enabledisable to the checkbox element
 * - add the class cq-dialog-checkbox-enabledisable-target to each target component that can be enabled/disabled
 */
(function(document, $) {
    "use strict";

    // when dialog gets injected
    $(document).on("foundation-contentloaded", function(e) {
        // if there is already an inital value make sure the according target element becomes visible
        enableDisable($(".cq-dialog-checkbox-enabledisable", e.target));
    });

    $(document).on("change", ".cq-dialog-checkbox-enabledisable", function(e) {
        enableDisable($(this));
    });

    function enableDisable(el){
        el.each(function(i, element) {
            if ($(element).attr("type") === "checkbox"){
                if ($(element).prop('checked')){
                    $('.cq-dialog-checkbox-enabledisable-target').enable();
                } else {
                    $('.cq-dialog-checkbox-enabledisable-target').disable();
                }
            }
        })
    }
    //recurse all pathbrowser children and grandchildren etc
    function iteratePathBrowserDescendants (node, enable) {
        for (var i = 0; i < node.childNodes.length; i++) {
            var child = node.childNodes[i];
            if ((child.className.indexOf('js-coral-pathbrowser-input') > -1 ) || (child.className.indexOf('js-coral-pathbrowser-button') > -1 )) {
                enablePathBrowser(child, enable);
            } else {
                iteratePathBrowserDescendants(child, enable);
            }
        }
    }
    function enablePathBrowser(node, enable) {
        node.disabled = enable;
    }

    //iterate class cq-dialog-checkbox-enabledisable-target's and enable
    $.prototype.enable = function () {
        $.each(this, function (index, el) {
            //special treatment for pathBrowser as it is made up of multiple fields and cannot be disabled at the top level
            if (el.hasAttribute('data-init')) {
                if (el.getAttribute('data-init') == 'pathbrowser'){
                    iteratePathBrowserDescendants(el, false);
                };
            } else {
                el.disabled = false;
            }
        });
    }
    //iterate class cq-dialog-checkbox-enabledisable-target's and disable
    $.prototype.disable = function () {
        $.each(this, function (index, el) {
            //special treatment for pathBrowser as it is made up of multiple fields and cannot be disabled at the top level
            if (el.hasAttribute('data-init')) {
                if (el.getAttribute('data-init') == 'pathbrowser'){
                    iteratePathBrowserDescendants(el, true);
                };
            } else {
                el.disabled = true;
            }
        });
    }
})(document,Granite.$);