Custom validation function for each "xtype=textfield" within the "xtype=multifield" | Community
Skip to main content
Peter_Puzanovs
Community Advisor
Community Advisor
October 16, 2015
Solved

Custom validation function for each "xtype=textfield" within the "xtype=multifield"

  • October 16, 2015
  • 3 replies
  • 2340 views

Hi,

The task is to validate each textfield found in the multifield,

<urls jcr:primaryType="cq:Widget" fieldDescription="Click the '+' to add a multiple urls.." fieldLabel="Urls  (Without etxn.)" name="./Urls" xtype="multifield"> <url jcr:primaryType="cq:Widget" fieldLabel="Url" width="155" validator="function(validateValue) { console.log(validateValue); return 'Would expect this check to be invoked';}" xtype="textfield"/> </urls>

Currently it does not seem to validate the textfield, is there a work around that would get it running through the validator ?

 

Thanks,

Peter

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 Ove_Lindström

I think I solved it. I added this to my multifield node:

< listeners jcr:primaryType="nt:unstructured" beforeadd="function(list,component,index){if(index!=0){var link=list.items.item(index-1).getValue();var myObject=JSON.parse(link);if(link.text==''){CQ.Ext.Msg.show({title:'Validation Error',msg:'Link Text can not be empty!',buttons:CQ.Ext.MessageBox.OK,icon:CQ.Ext.MessageBox.ERROR});return false;}if(link.url==''){CQ.Ext.Msg.show({title:'Validation Error',msg:'URL can not be empty!',buttons:CQ.Ext.MessageBox.OK,icon:CQ.Ext.MessageBox.ERROR});return false;}}}"/>

Found the solution at http://helpx.adobe.com/adobe-cq/using/tips-tricks.html

3 replies

Level 6
October 16, 2015

You can't add a validator to the multifield since the multifield widget don't really know about the underlying xtype. I think you need to add it to the child-types field config.

Edit: And that is what you have done...

Ove_LindströmAccepted solution
Level 6
October 16, 2015

I think I solved it. I added this to my multifield node:

< listeners jcr:primaryType="nt:unstructured" beforeadd="function(list,component,index){if(index!=0){var link=list.items.item(index-1).getValue();var myObject=JSON.parse(link);if(link.text==''){CQ.Ext.Msg.show({title:'Validation Error',msg:'Link Text can not be empty!',buttons:CQ.Ext.MessageBox.OK,icon:CQ.Ext.MessageBox.ERROR});return false;}if(link.url==''){CQ.Ext.Msg.show({title:'Validation Error',msg:'URL can not be empty!',buttons:CQ.Ext.MessageBox.OK,icon:CQ.Ext.MessageBox.ERROR});return false;}}}"/>

Found the solution at http://helpx.adobe.com/adobe-cq/using/tips-tricks.html

Peter_Puzanovs
Community Advisor
Community Advisor
October 16, 2015

Yup, the listener did it's magic,

Thank you Ove !

 

Peter