Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Content Fragment: Custom Content Reference Field Validation (AEM 6.4)

AEMRand
Level 2
Level 2

Hello, 

I have a content fragment model that leverages a content reference field as such...

 

 

<_x0031_597244630515
                            jcr:primaryType="nt:unstructured"
                            sling:resourceType="dam/cfm/models/editor/components/contentreference"
                            fieldLabel="Product Name"
                            listOrder="27"
                            metaType="reference"
                            name="richproductName"
                            nameSuffix="contentReference"
                            required="on"
                            renderReadOnly="false"
                            showEmptyInReadOnly="true"
                            valueType="string"/>

 

 

I see that with the addition of the rootPath attribute, I can limit the directory to where a reference can be made. However, this doesnt stop someone from linking to something in the directory that shouldn't be there (say if someone creates an invalid experience fragment.) Is there a way to add some kind of validation/code that I can run when someone selects something from the content reference field? 

6.4 content fragment content reference
1 Accepted Solution
BrianKasingli
Correct answer by
Community Advisor
Community Advisor

@AEMRand 

It is possible, I have provided a solution, please take a look here -> https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/ootb-validation-options-fo...

}}

In short, you can use JavaScript to append the "pattern" attribute to a given HTML element, from there it will enable HTML validation for the content fragment field itself; this is a regex pattern. Your client library should have a clientlib category of "dam.cfm.authoring.v2", so when you are on the cfm authoring view, your code will be run.

So you can imagine, anything that does not match ^/content/dam/my-site.+, then on-keyup, validation will fail, and the input field will be highlighted in red. 

View solution in original post

4 Replies
BrianKasingli
Correct answer by
Community Advisor
Community Advisor

@AEMRand 

It is possible, I have provided a solution, please take a look here -> https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/ootb-validation-options-fo...

}}

In short, you can use JavaScript to append the "pattern" attribute to a given HTML element, from there it will enable HTML validation for the content fragment field itself; this is a regex pattern. Your client library should have a clientlib category of "dam.cfm.authoring.v2", so when you are on the cfm authoring view, your code will be run.

So you can imagine, anything that does not match ^/content/dam/my-site.+, then on-keyup, validation will fail, and the input field will be highlighted in red. 

View solution in original post