How to limit the tags widget selecting a single value? | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
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

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
Translate
acrofatAuthor
New Participant
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?

Translate
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

Translate