Expand my Community achievements bar.

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

How to limit the tags widget selecting a single value?

Avatar

Level 1

We want the user only select one tag from the tags widget, how to config that?

 

thx

1 Accepted Solution

Avatar

Correct answer by
Level 7

Well I think in this case, what you would do is just to see if there is any tags added at all and the just pick the first one from the array: 
 

String[] tags = this.properties.get(TAGS_PROPERTY_NAME, new String[0]); String tag= ""; if(tags.length == 0){ //no tags have been added ! }else{ tag = tags[0]; } //Do something nice with your tag

View solution in original post

3 Replies

Avatar

Correct answer by
Level 7

Well I think in this case, what you would do is just to see if there is any tags added at all and the just pick the first one from the array: 
 

String[] tags = this.properties.get(TAGS_PROPERTY_NAME, new String[0]); String tag= ""; if(tags.length == 0){ //no tags have been added ! }else{ tag = tags[0]; } //Do something nice with your tag

Avatar

Level 1

Thx, this works. But what if I want to save the single tag as string in crx property, not as string[]? Is that possible?

Avatar

Level 7

There is an option/property in the tagInputField that allow you to choose how many tags to accept from a given namespace called "maximum". Set this one to "1" in your case. This has been somewhat explained in this blogpost:

http://cqsearchpromote.blogspot.se/2013/02/how-to-make-tag-input-field-accept.html

/Johan