How can we add a link (<a href>LINK</a>) in fieldDescription ? | Community
Skip to main content
airnavin30
Level 2
July 21, 2020
Solved

How can we add a link (<a href>LINK</a>) in fieldDescription ?

  • July 21, 2020
  • 5 replies
  • 6298 views

For one of the requirement, on a text field there is a help text with a reference link required to add, But with normal text with hyperlink it's showing as it is on hovering to [i] icon.

 

I have an understanding that hyperlink may not support here. Is there a way we can make a hyperlink ? or any alternative?

    

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 Suraj_Kamdi

@airnavin30 

Here is the solution 

1. Create one clientlibFolder 

2. set categories:[cq.authoring.editor]

3. create one add-field-desc.js

 

 

 

(function ($, $document) { "use strict"; // Load Json on dialog ready event $document.on("dialog-ready", function () { var $dataAttr = $('[data-custom-field-description]'); var fieldDescription = $dataAttr.data('custom-field-description'); var $coralIcon = $dataAttr.siblings('coral-icon'); $coralIcon.on('click', function(){ $dataAttr.siblings('coral-tooltip').html(fieldDescription); }); }); })($, $(document));

 

 

 

4. create js.txt and add add-field-desc.js path

5. Now go to your field where you want to add field description.

6. create one child node with name granite:data and set custom-field-description="Hey adding <a href="#">link" </a>

7. your structure should look like

 

 

 

<cq:dialog> ----- <your-field jcr:primaryType="nt:unstructured" fieldLabel="Your Field" sling:resourceType="granite/ui/components/coral/foundation/form/textfield" fieldDescription="" name="./yourField"> <granite:data custom-field-description="hey adding <a href="#"> link <a/>" /> </your-field>

 

 

 

 

5 replies

ArpitVarshney
Community Advisor
Community Advisor
July 21, 2020

Hi @airnavin30

You can implement the rich text editor (rte) inside a dialog for this requirement. Go through below blogs

 

Also, You might think of giving the HTML itself in the text field and read in HTL using @context='html' but this is not recommended at all. I've seen many people doing this but this is not good from a security point of view. You will give the author to do anything.

 

Regards,

Arpit Varshney

airnavin30
Level 2
July 21, 2020
Probably, it's misunderstood what I am asking about
Vaibhavi_J
Level 7
July 21, 2020

Hi @airnavin30 , 

 

Yes it is possible. We can add link in filed description. 

It works fine for me. I have added anchor link navigation to google.com in field description and it works as expected. 

 

 

 

Please do have a check if you have made any syntax error. Also, please do inspect of anchor and verify if DOM for anchor is constructed fine.

 

Suraj_Kamdi
Community Advisor
Community Advisor
July 21, 2020

Hello @airnavin30

You need to write custom JS to add text with a hyperlink by specifying the categories:[cq.authoring.editor]

 

Please let me know if you need more help with this. I am happy to help 🙂 

Suraj_Kamdi
Community Advisor
Suraj_KamdiCommunity AdvisorAccepted solution
Community Advisor
July 21, 2020

@airnavin30 

Here is the solution 

1. Create one clientlibFolder 

2. set categories:[cq.authoring.editor]

3. create one add-field-desc.js

 

 

 

(function ($, $document) { "use strict"; // Load Json on dialog ready event $document.on("dialog-ready", function () { var $dataAttr = $('[data-custom-field-description]'); var fieldDescription = $dataAttr.data('custom-field-description'); var $coralIcon = $dataAttr.siblings('coral-icon'); $coralIcon.on('click', function(){ $dataAttr.siblings('coral-tooltip').html(fieldDescription); }); }); })($, $(document));

 

 

 

4. create js.txt and add add-field-desc.js path

5. Now go to your field where you want to add field description.

6. create one child node with name granite:data and set custom-field-description="Hey adding <a href="#">link" </a>

7. your structure should look like

 

 

 

<cq:dialog> ----- <your-field jcr:primaryType="nt:unstructured" fieldLabel="Your Field" sling:resourceType="granite/ui/components/coral/foundation/form/textfield" fieldDescription="" name="./yourField"> <granite:data custom-field-description="hey adding <a href="#"> link <a/>" /> </your-field>

 

 

 

 

airnavin30
Level 2
July 22, 2020
Thanks a lot Suraj , I tried that and it worked !
arunpatidar
Community Advisor
Community Advisor
July 21, 2020

Hi,

OOTB it is not possible, There are three options:

1. Remove fieldDescription encoding from render.jsp so that it can allow rich-text.

2. Use custom js solution similar suggested by @suraj_kamdi 

3. Use Heading for text and Hyperlink resourceType to create a link in the dialog.

 

I would say go for option 2 or 3 if the objective is just to show link.

Arun Patidar