selectionchanged事件不工作 [英] selectionchanged event is not working

查看:252
本文介绍了selectionchanged事件不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的对话框中有两个脚垫,一个是文本字段(leftpadding),另一个是四个选项的下拉列表(选项1,选项2,选项3,选项4)。我的要求是显示/启用textfiled用户仅选择选项3和选项4。
我添加了listeners(selectedchanged)节点到下拉字段。 loadcontent事件正在触发,但是selectedchanged是不正常的。请在下面找到代码片段



choosechanged:

  function字段,值){

var layoutoption =;
layoutoption = field.findParentByType('dialog')。form.findField('./ footerstyle')。getValue();
alert('layoutoption:'+ layoutoption);
if(layoutoption =='3'|| layoutoption =='4'){
field.findParentByType('dialog')。form.findField('./ leftPadding')。enable(this) ;
} else {
field.findParentByType('dialog')。form.findField('./ leftPadding')。disable(this);
}}


解决方案

CQ.form.Selection API,您会发现当 selectionchanged 事件被触发时,以下参数将被传递给侦听器。




  • :选择字段

  • :所选字段的原始值

  • isChecked :true / false,当选择类型为复选框时使用。



因此,您可以修改您的监听器,如下所示。

  function(field,value){
var dlg = field .findParentByType( '对话');
//该值保存选择的值
if(value =='3'|| value =='4'){
//对话框类的getField()返回具有给定名称的字段
dlg.getField('./ leftPadding')。show();
} else {
dlg.getField('./ leftPadding')。hide();
}
}

CQ.Dialog 返回字段与给定的名称。如果存在多个具有相同名称的字段,则返回这些字段的数组。您可以根据需要显示()或隐藏()字段。



编辑
CQ 5.4以某种方式t删除整个小部件,而不是仅删除输入字段,留下字段标签,说明等。



在这种情况下,可以使用以下功能。

  function(field,value){
var dlg = field.findParentByType('dialog');
if(value =='3'|| value =='4'){
dlg.getField('./ leftPadding')。el.parent('。x-form-item') 。显示();
}
else {
dlg.getField('./ leftPadding')。el.parent('。x-form-item')hide();
}
}


I have two felds in my dialog, one is text field(leftpadding) and another is dropdown with four options(option 1, option 2, option 3, option 4).My requirement is to display/enable the textfiled when the user selects option 3 and option 4 only. I added listeners(selectionchanged) node to the dropdown field. loadcontent event is firing but selectionchanged is not working fine. Please find below for the code snippet

selectionchanged:

function(field,value){ 

var layoutoption = "";
layoutoption = field.findParentByType('dialog').form.findField('./footerstyle').getValue();
alert('layoutoption :'+layoutoption);
if(layoutoption =='3' || layoutoption =='4'){
    field.findParentByType('dialog').form.findField('./leftPadding').enable(this);
}else {
    field.findParentByType('dialog').form.findField('./leftPadding').disable(this);
}}

解决方案

If you look at the CQ.form.Selection API, you would find that when the selectionchanged event is fired, the following arguments would be passed to the listener.

  • this : The selection field
  • value : The raw value of the selected field
  • isChecked : true / false, used when the selection is of type checkbox.

Thus, you could modify your listener as shown below.

function(field, value) { 
    var dlg = field.findParentByType('dialog');
    // the value holds the value of the selection
    if(value =='3' || value =='4'){
        // getField() of the dialog class returns the field with the given name
        dlg.getField('./leftPadding').show();
    }else {
        dlg.getField('./leftPadding').hide();
    }
}

The getField() method of the CQ.Dialog returns the field with the given name. In case more than one field with the same name exists, it returns an array of those fields. You can then show() or hide() the fields based on your requirements.

EDIT : CQ 5.4 somehow doesn't remove the entire widget, instead removes only the input field leaving behind the Field Label, Description etc.

In such cases the following function may be used.

function(field, value) {
    var dlg = field.findParentByType('dialog');
    if(value == '3' || value == '4') {
        dlg.getField('./leftPadding').el.parent('.x-form-item').show();
    }
    else { 
        dlg.getField('./leftPadding').el.parent('.x-form-item').hide();
    }
}

这篇关于selectionchanged事件不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆