【问题标题】:Conditionally enable/disable fields in AEM 6.1 (granite.ui) TouchUI dialogs有条件地启用/禁用 AEM 6.1 (granite.ui) TouchUI 对话框中的字段
【发布时间】:2015-10-17 04:12:32
【问题描述】:

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

为了提供一些上下文,我在我的 TouchUI 对话框中有一个复选框,用于启用/禁用(隐藏/显示)组件中的 Call To Action 按钮。我想禁用对话框本身中的 CTA buttonText 和 href 字段,作者通过复选框禁用了 CTA。不利的是,我想在选中 CTA 复选框以启用 CTA 的情况下启用这些字段。

我已经调查了 /libs/cq/gui/components/authoring/dialog/dropdownshowhide/clientlibs/dropdownshowhide.js 但它并不真正适合目的,因为这是专门为根据下拉列表的值隐藏或显示字段而设计的我尝试修改它以允许在复选框上实现类似的功能性并没有取得丰硕的成果。我想启用/禁用字段而不是隐藏或显示它们。

【问题讨论】:

标签: adobe aem


【解决方案1】:

经过一番折腾后,我通过将 class="cq-dialog-checkbox-enabledisable" 添加到我的 sling:resourceType="granite/ui/components/foundation/form/checkbox" 和 class="cq -dialog-checkbox-enabledisable-target" 到我想在我的 cq:dialog.xml 中禁用的 sling:resourceType="granite/ui/components/foundation/form/textarea"。

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

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

  

  /**
 * 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.$);

【讨论】:

  • 你能分享你的 .content.xml 文件吗?
  • @Jdruwe,我假设您的意思是 clientLib 的 .content.xml ? day.com/jcr/cq/1.0" xmlns:jcr="jcp.org/jcr/1.0" jcr:primaryType="cq:ClientLibraryFolder" categories= "cq.authoring.dialog" 依赖项="[granite.jquery]"/>
  • @Jdruwe,希望这会有所帮助,顺便说一句,请注意上面 clientLib 的更新,以适应路径浏览器字段的启用/禁用
  • 如果你修改它,你不会破坏你的升级路径吗?
  • @TyMayn 不,这是一个自定义的clientLib,有效地扩展了cq.authoring.dialog的功能
猜你喜欢
  • 1970-01-01
  • 2016-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多