Expand my Community achievements bar.

SOLVED

Compare and show error message

Avatar

Level 4

In my dialog i created selection and i gave options.

First time i can select options from selection box, if next time some one is trying to select the same option, i need to show error message like already exist.

How i can achieve this, please need input to proceed.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Here is the code for your use case, its ready to execute. 

i have used 2 listeners, and keeping track of previously selected value in a hidden node.

<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" jcr:primaryType="cq:Dialog" modal="{Boolean}true" title="Text" width="800" xtype="dialog"> <items jcr:primaryType="cq:Widget" xtype="tabpanel"> <items jcr:primaryType="cq:WidgetCollection"> <advanced jcr:primaryType="cq:Panel" title="Advanced Properties"> <items jcr:primaryType="cq:WidgetCollection"> <target jcr:primaryType="cq:Widget" fieldDescription="Select target for the url" fieldLabel="Target" name="./target" type="select" xtype="selection"> <options jcr:primaryType="cq:WidgetCollection"> <samewindow jcr:primaryType="cq:Widget" text="Same window" value="_self"/> <newwindow jcr:primaryType="cq:Widget" text="New window" value="_blank"/> </options> <listeners jcr:primaryType="nt:unstructured" selectionchanged="function(comp, val, isChecked) {console.log("selected"+val);d = comp.findParentByType("dialog").getField("./hidevalue"); console.log(d.getValue());x=d.getValue(); if(x==val) { alert("Same value selected"); }}"/> </target> <hidden jcr:primaryType="cq:Widget" name="./hidevalue" xtype="hidden"/> </items> </advanced> </items> </items> <listeners jcr:primaryType="nt:unstructured" beforesubmit="function(dialog){console.log("Closed");d = dialog.getField("./target"); console.log(d.getValue()); h = dialog.getField("./hidevalue"); h.setValue(d.getValue());};"/> </jcr:root>

View solution in original post

4 Replies

Avatar

Level 10

Add a node name "listeners" in your dropdown node in crxde as a child node and then add a "selectionchanged " type of listener.

Here is the API Documentation

It will be something similar to this: 

<dialog jcr:primaryType="cq:Dialog" title="Test Component" xtype="panel"> <items jcr:primaryType="cq:WidgetCollection"> <title jcr:primaryType="cq:Widget" fieldLabel="Selection" name="./sel" type="select" xtype="selection"> <listeners jcr:primaryType="nt:unstructured" selectionchanged="function(comp, val, isChecked) {console.log("selected");}"/> <options jcr:primaryType="cq:WidgetCollection"> <opt1 jcr:primaryType="nt:unstructured" text="Option 1" value="1"/> <opt2 jcr:primaryType="nt:unstructured" text="Option 2" value="2"/> <opt3 jcr:primaryType="nt:unstructured" text="Option 3" value="3"/> </options> </title> </items> </dialog>

Avatar

Level 4

Thanks for the reply.

Am getting alert for all the selection change.

But i need to give condition, can i check conditions in xml?

If the property already exist, i need to show error or else i don't want to show error message / alert message.

Ex : If they select option 1 for first time -- it will store in crx, 

Second time they are trying to select same option, then i need to show error message.

Avatar

Correct answer by
Level 10

Here is the code for your use case, its ready to execute. 

i have used 2 listeners, and keeping track of previously selected value in a hidden node.

<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" jcr:primaryType="cq:Dialog" modal="{Boolean}true" title="Text" width="800" xtype="dialog"> <items jcr:primaryType="cq:Widget" xtype="tabpanel"> <items jcr:primaryType="cq:WidgetCollection"> <advanced jcr:primaryType="cq:Panel" title="Advanced Properties"> <items jcr:primaryType="cq:WidgetCollection"> <target jcr:primaryType="cq:Widget" fieldDescription="Select target for the url" fieldLabel="Target" name="./target" type="select" xtype="selection"> <options jcr:primaryType="cq:WidgetCollection"> <samewindow jcr:primaryType="cq:Widget" text="Same window" value="_self"/> <newwindow jcr:primaryType="cq:Widget" text="New window" value="_blank"/> </options> <listeners jcr:primaryType="nt:unstructured" selectionchanged="function(comp, val, isChecked) {console.log("selected"+val);d = comp.findParentByType("dialog").getField("./hidevalue"); console.log(d.getValue());x=d.getValue(); if(x==val) { alert("Same value selected"); }}"/> </target> <hidden jcr:primaryType="cq:Widget" name="./hidevalue" xtype="hidden"/> </items> </advanced> </items> </items> <listeners jcr:primaryType="nt:unstructured" beforesubmit="function(dialog){console.log("Closed");d = dialog.getField("./target"); console.log(d.getValue()); h = dialog.getField("./hidevalue"); h.setValue(d.getValue());};"/> </jcr:root>