繁体   English   中英

CQ5对话框不起作用

[英]CQ5 Dialog not working

我正在学习CQ5,但仍无法创建对话框验证。 我的JavaScript在clientlibs文件夹中,并且正在使用侦听器来调用该函数,但并未被调用。 我看不到任何验证。

如果提供了相应的ID,我试图将URL字段设置为必填。

以下是我的JS代码。

var fieldsetCheck = {};

fieldsetCheck.chkBlankFields  = function chkBlankFields(panel) {

    var fieldSets = panel.findByType('dialogfieldset');
    var fLength = fieldSets.length;

    for (var i = 0; i < fLength; i++) {
        var fieldSet = fieldSets[i];
        var Id = panel.getComponent('Id'+(i++));
        var Url = panel.getComponent('Url'+(i++)); 

        if(Id.getValue().trim() !== ""||Url.getValue().trim()!=="") { 
            campId.allowBlank = false;
            campUrl.allowBlank = false;
        } else {
            campId.allowBlank = true;
            campUrl.allowBlank = true;
        }
    }    
}

这是我的dialog.xml

<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0"zzzmlns:jcr="http://www.jcp.org/jcr/1.0" jcr:primaryType="cq:Dialog" height="500" id="textNavEditDialog" title="Test Configuration Dialog" width="600" xtype="dialog">
    <items jcr:primaryType="cq:WidgetCollection">
        <tabs jcr:primaryType="cq:TabPanel" activeTab="{Long}0" title="Test Configuration" xtype="tabpanel">
            <items jcr:primaryType="cq:WidgetCollection">
                <campaigns jcr:primaryType="cq:Widget" title="Links" xtype="panel">
                    <items jcr:primaryType="cq:WidgetCollection">
                            <fieldsetDialog1 jcr:primaryType="cq:Widget" xtype="dialogfieldset" border="{Boolean}true" collapseFirst="{Boolean}true" collapsed="{Boolean}false" collapsible="{Boolean}false"  hideLabel="{Boolean}false" id="fieldset1">
                                <items jcr:primaryType="cq:WidgetCollection">

                                    <Id1 jcr:primaryType="cq:Widget" fieldDescription="Enter segment only (exclude seg=)" fieldLabel="Segment Number 1" allowBlank="{Boolean}false" maxLength="12" name="./sc:Id1" nanText="Please enter a numeric value" xtype="numberfield" ItemId ="Id1"/>
                                    <Url1 jcr:primaryType="cq:Widget" fieldDescription="Path to Campaign 1" fieldLabel="Campaign URL 1" allowBlank="{Boolean}false" name="./sc:Url1" predicate="hierarchy" suffix="/_jcr_content/par.html" typeAhead="{Boolean}false" xtype="pathfield" ItemId ="Url1"/>
                                </items>
                            </fieldsetDialog1>

                            <fieldsetDialog2 jcr:primaryType="cq:Widget" xtype="dialogfieldset" border="{Boolean}true" collapseFirst="{Boolean}true" collapsed="{Boolean}false" collapsible="{Boolean}false"  hideLabel="{Boolean}false" id="fieldset2">
                                <items jcr:primaryType="cq:WidgetCollection">

                                    <Id2 jcr:primaryType="cq:Widget" fieldDescription="Enter segment only (exclude seg=)" fieldLabel="Segment Number 2" maxLength="12" name="./sc:Id2" nanText="Please enter a numeric value" xtype="numberfield" ItemId ="Id2"/>
                                    <Url2 jcr:primaryType="cq:Widget" fieldDescription="Path to Campaign 2" fieldLabel="Campaign URL 2" name="./sc:Url2" predicate="hierarchy" suffix="/_jcr_content/par.html" typeAhead="{Boolean}false" xtype="pathfield" ItemId = "Url2" />
                                </items>

                            </fieldsetDialog2>

                            <fieldsetDialog3 jcr:primaryType="cq:Widget" xtype="dialogfieldset" border="{Boolean}true" collapseFirst="{Boolean}true" collapsed="{Boolean}false" collapsible="{Boolean}false"  hideLabel="{Boolean}false" id="fieldset3">
                                <items jcr:primaryType="cq:WidgetCollection">

                                    <Id3 jcr:primaryType="cq:Widget" fieldDescription="Enter segment only (exclude seg=)" fieldLabel="Segment Number 3" maxLength="12" name="./sc:Id3" nanText="Please enter a numeric value" xtype="numberfield" ItemId ="Id3" />
                                    <Url3 jcr:primaryType="cq:Widget" fieldDescription="Path to Campaign 3" fieldLabel="Campaign URL 3" name="./sc:Url3" predicate="hierarchy" suffix="/_jcr_content/par.html" typeAhead="{Boolean}false" xtype="pathfield" ItemId ="Url3"/>
                                </items>
                            </fieldsetDialog3>
                    </items>
                    <listeners jcr:primaryType="nt:unstructured" beforesubmit="function(this) { fieldsetCheck.chkBlankFields(this);}" />
                </campaigns>
            </items>
        </tabs>
    </items>
</jcr:root>

Panel xtype没有beforesubmit事件。 该事件仅适用于对话框 xtype。 侦听器必须是对话框节点的子节点。

该函数将以对话框作为参数而不是面板来调用。 由于您在函数中使用findByType()方法仍然可以正常工作,因此只需将变量重命名为dialog以提高可读性即可。

我看到的是,增加id和url存在问题,因为两个语句中都有i ++导致每次迭代增加2个额外增量,因此在第二次迭代中,该值将是3而不是1,依此类推。 所以,我建议以下代码

  for (var i = 0; i < fLength; i++) 
  {
        var fieldSet = fieldSets[i];
        var Id = panel.getComponent('Id'+(i + 1));
        var Url = panel.getComponent('Url'+(i + 1)); 

        if(Id.getValue().trim() !== ""||Url.getValue().trim()!=="")
        { 
            campId.allowBlank = false;
            campUrl.allowBlank = false;
        } 
        else 
        {
            campId.allowBlank = true;
            campUrl.allowBlank = true;
        }
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM