我正在學習CQ5,並且我被困在創建對話框驗證。我的JavaScript位於clientlibs文件夾中,我正在使用偵聽器來調用該函數,但它沒有被調用。我看不到驗證。CQ5對話框不工作
我想提供相應的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>
JavaScript不是Java,所以我已經從你的帖子中刪除了[tag:java]標籤。 – hexafraction
謝謝!認爲CQ5具有Java框架及其相關 – maddy