Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

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

Avatar

Community Advisor

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

1 Accepted Solution

Avatar

Correct answer by
Level 6

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

View solution in original post

3 Replies

Avatar

Level 6

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...

Avatar

Correct answer by
Level 6

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

Avatar

Community Advisor

Yup, the listener did it's magic,

Thank you Ove !

 

Peter