Created
May 28, 2015 10:19
-
-
Save willtonkin/fe858cd804860c79e717 to your computer and use it in GitHub Desktop.
Advanced AEM dialog validation Example - includes RegEx field check and complicated logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" | |
jcr:primaryType="cq:Dialog" | |
title="My Dialog" | |
xtype="dialog"> | |
<items | |
jcr:primaryType="cq:Widget" | |
xtype="tabpanel"> | |
<items jcr:primaryType="cq:WidgetCollection"> | |
<tab1 | |
jcr:primaryType="cq:Panel" | |
title="tab 1"> | |
<items jcr:primaryType="cq:WidgetCollection"> | |
<link | |
jcr:primaryType="cq:Widget" | |
fieldLabel="Link" | |
name="./link" | |
xtype="pathfield"/> | |
<enable | |
jcr:primaryType="cq:Widget" | |
defaultValue="{Boolean}false" | |
fieldLabel="Enable" | |
name="./enable" | |
type="checkbox" | |
xtype="selection"/> | |
</items> | |
</tab1> | |
</items> | |
</items> | |
<listeners | |
jcr:primaryType="nt:unstructured" | |
beforesubmit=" | |
function(dialog) { | |
var linkField = dialog.find('name', './link')[0]; | |
var enableField = dialog.find('name', './enable')[0]; | |
var linkVal = linkField.getValue().trim(); | |
var enableVal = enableField.getValue(); | |
/* matches NOT starting with '/content/' or ending with '.html' or '/' */ | |
var reFail = new RegExp('(^(?!\/content\/)(.*))|(\.htm.?$)|(\/$)', 'i'); | |
if(reFail.test(linkVal) && enableVal == 'true') { | |
CQ.Ext.Msg.alert('Validation', 'Link should not be an external path or include a .html or / at the end.'); | |
return false; | |
} | |
return true; | |
}"/> | |
</jcr:root> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment