有人有根据 AEM6.1 TouchUI 对话框中先前字段的值有条件禁用字段的经验吗?
为了提供一些上下文,我的 TouchUI 对话框中有一个复选框,用于启用/禁用(隐藏/显示)组件内的“调用操作”按钮。我想禁用对话框本身中的 CTA 按钮文本和 href 字段,其中作者已通过复选框禁用了 CTA。相反,我想在选中 CTA 复选框以启用 CTA 的情况下启用这些字段。
我已经调查了 /libs/cq/gui/components/authoring/dialog/dropdownshowhide/clientlibs/dropdownshowhide.js 但它并不真正适合目的,因为这是专门为根据下拉列表的值和我的尝试隐藏或显示字段而设计的修改它以允许在复选框上实现类似的功能并没有取得什么成果。我想启用/禁用字段而不是隐藏或显示它们。
经过一番混乱后,我通过将 class="cq-dialog-checkbox-enabledisable" 添加到我的吊带中来完成这项工作: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。
更新:事实证明,禁用属性无法在顶层的 pathbrowser 字段类型上以编程方式设置,因此您需要禁用其中包含的子字段(js-coral-pathbrowser-input 和 js-coral-pathbrowser-button)下面的代码片段已更新以反映这一点。
/**
* 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.$);Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15210 次 |
| 最近记录: |