Solved
Server Side Validation for a Widget
Hi,
Is there any example on how do we do a server side validation and send the message accordingly to a widget
Hi,
Is there any example on how do we do a server side validation and send the message accordingly to a widget
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; | ||
| }; |
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.