How to limit the tags widget selecting a single value? | Community
Skip to main content
October 16, 2015
Solved

How to limit the tags widget selecting a single value?

  • October 16, 2015
  • 3 replies
  • 755 views

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

 

thx

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 Ojjis

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

3 replies

Ojjis
OjjisAccepted solution
Level 7
October 16, 2015

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
acrofatAuthor
October 16, 2015

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

Ojjis
Level 7
October 16, 2015

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