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

How to set default value for tag picker

jerryru
Level 2
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
jerryru
Correct answer by
Level 2
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
smacdonald2008
Level 10
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...

kautuk_sahni
Community Manager
Community Manager

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
jerryru
Level 2
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.

jerryru
Level 2
Level 2

Thanks for your response and sharing. Really appreciate!!

Hemant_arora
Level 8
Level 8

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

smacdonald2008
Level 10
Level 10

Keep in mind xtype is for Classic UI.

amanagarwal
Level 3
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);

     }

}

jerryru
Correct answer by
Level 2
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