Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to set default value for tag picker

Avatar

Level 2

I want to set a default value for my cq:tag which is using a tagpicker (cq/gui/components/common/tagspicker). Is there anyone know how to configure it? I am using AEM 6.3 touch UI.

1 Accepted Solution

Avatar

Correct answer by
Level 2

I made it by adding listeners.js in clientlins folder to the component. The following is example:

$document.on("dialog-ready", function() {

       // add logic here

    });

View solution in original post

8 Replies

Avatar

Level 10

I am not aware of how to set a default - when you click on this field - it opens the JCR dialog where an author selects tags,

TagsDialog2.png

A community article that uses tag picker -- Adobe Experience Manager Help | Developing HTML Template Language Components that search for Adobe E...

Avatar

Administrator

I would recommend you to have a look at this documentation: Overview of the Tagging API

The implementation of the tagging framework  in AEM allows management of tags and tag content using the JCR API . The TagManager ensures that tags entered as values on the cq:tags string array property are not duplicated, it removes TagIDs pointing to non-existing tags and updates TagIDs for moved or merged tags. TagManager uses a JCR observation listener that reverts any incorrect changes. The main classes are in the com.day.cq.tagging package:

  • JcrTagManagerFactory - returns a JCR-based implementation of a TagManager. It is the reference implementation of the Tagging API.
  • TagManager -  allows for resolving and creating tags by paths and names.
  • Tag - defines the tag object


Kautuk Sahni

Avatar

Level 2

Thanks for your response. I want to set a default value on my "cq:tags" field of my component via dialog configurations. Is it possible? I am trying to set a "value" or "defaultValue". Unfortunately, both of them don't work.

Avatar

Level 2

Thanks for your response and sharing. Really appreciate!!

Avatar

Level 9

Set the default value  and

Add a listeners node to your xtype tags and add the loadcontent function to your listener

Working example : function(field){var x=[field.defaultValue];field.setValue(x);}

Further u can tweak the loadcontent function to retrieve the new selected values

1343779_pastedImage_0.png

1343786_pastedImage_1.png

Avatar

Level 10

Keep in mind xtype is for Classic UI.

Avatar

Level 3

A small tweak to the Listener, just to avoid showing the defaultValue even after modifying the Tag Field values.

'tagname' is name of the tag.

function(field, record)

{

     if(record.get('tagname') == undefined)

     {

          var x=[field.defaultValue];

          field.setValue(x);

     }

}

Avatar

Correct answer by
Level 2

I made it by adding listeners.js in clientlins folder to the component. The following is example:

$document.on("dialog-ready", function() {

       // add logic here

    });