Server Side Validation for a Widget | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by gopalKa

Typically for fields you can add a validator attribute that calls a js function which can call a servlet. But.,if there is no validator function, you can do as below as well.

Add a listener as an unstructured node to the dialog like 

            
<listeners
 jcr:primaryType="nt:unstructured"
 beforesubmit="function(dialog){ return validateDialog(dialog); }"/>

In your js , make your ajax call.. This is just an example 

 

                                                                         
validateDialog = function(dialog) {
 var fields = dialog.findByType("numberfield"),
 expectedTotal = 100,
 width = 0;
  
 var width;
$.ajax("/bin/validatewidth",data:data,function(response){

width= response.width;
});
 
  
 if (width !== expectedTotal) {
 CQ.Ext.Msg.show({
 title:'Validation Error',
 msg:'Total width of all columns needs to be exactly 100 percent!',
 buttons: CQ.Ext.MessageBox.OK,
 icon:CQ.Ext.MessageBox.ERROR
 });
 return false;
 }
 return true;
 };

3 replies

smacdonald2008
Level 10
October 16, 2015

Can you please explain your use case in more detail please. 

Lokesh_Shivalingaiah
Level 10
October 16, 2015

Hi Scott,

Here is what I would like to do

1. Textarea widget in a dialog. Authors enters some 'String'

2. Need to send this 'String' to OSGi layer, do some business logic validation and send back the message to the Dialog.

3. Display that message on the dialog for Authors.

gopalKaAdobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

Typically for fields you can add a validator attribute that calls a js function which can call a servlet. But.,if there is no validator function, you can do as below as well.

Add a listener as an unstructured node to the dialog like 

            
<listeners
 jcr:primaryType="nt:unstructured"
 beforesubmit="function(dialog){ return validateDialog(dialog); }"/>

In your js , make your ajax call.. This is just an example 

 

                                                                         
validateDialog = function(dialog) {
 var fields = dialog.findByType("numberfield"),
 expectedTotal = 100,
 width = 0;
  
 var width;
$.ajax("/bin/validatewidth",data:data,function(response){

width= response.width;
});
 
  
 if (width !== expectedTotal) {
 CQ.Ext.Msg.show({
 title:'Validation Error',
 msg:'Total width of all columns needs to be exactly 100 percent!',
 buttons: CQ.Ext.MessageBox.OK,
 icon:CQ.Ext.MessageBox.ERROR
 });
 return false;
 }
 return true;
 };