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

标签 adobe aem

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

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

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

最佳答案

经过一番困惑之后,我通过将 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。

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

  

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

关于adobe - 有条件地启用/禁用 AEM 6.1 (granite.ui) TouchUI 对话框中的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31645244/

相关文章:

java - AEM session 对象未被垃圾收集

google-analytics - 您可以以编程方式创建测试和目标插件吗?

adobe - "var"是什么时候解析的?

aem - 有没有办法知道我们是在 Touch UI 中打开页面还是在 javascript 中打开经典 UI

aem - Sling resource.getResourceResolver() 与 SlingHttpRequest.getResourceResolver

java - cq5。如何显示作者的出版商列表? 5.5版本

javascript - Adobe PDF Javascript 提取名称,保存文件

android - 相机胶卷图库链接?!土坯空气

ios - Adobe Air ios 打包程序

单击复选框时,AEM 中的 Javascript 添加类