How to restrict number of tags we are able to select in the component dialog | Community
Skip to main content
Level 9
June 6, 2016
Solved

How to restrict number of tags we are able to select in the component dialog

  • June 6, 2016
  • 13 replies
  • 7096 views

Hi All,

In our component dialog.xml, we currently have the below :

<tags
                    jcr:primaryType="cq:Widget"
                    cls="cq-propsdialog-tags"
                    fieldLabel="Tags"
                    name="./cq:tags"
                    xtype="tags"/>

#1] We should be able to restrict the tags we are able to select in the dialog to 3. Saw a similar article https://forums.adobe.com/thread/1175413, but on trying that , it doesn't seem to be working correctly.

#2] Also, an additional query : what should be done if we have to restrict 3 tags per namespace.

if you can let me know the changes that have to be made to the dialog structure/reference articles, it would be helpful.

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 askdctm

Hi All, 

Tried writing a listener making use of addtag() event in Tagfield, but it is failing in all scenarios except one. Basically, is of no use in real world-scenarios.

Any snippet/reference would be helpful.

13 replies

Kunal_Gaba_
June 6, 2016
<tagsjcr:primaryType="cq:Widget"fieldLabel="Tags"name="./tags"xtype="tags"><namespaces jcr:primaryType="cq:WidgetCollection"><topic1 jcr:primaryType="nt:unstructured" maximum="3" name="topic1" />        <topic2 jcr:primaryType="nt:unstructured" maximum="3" name="topic2" />
</namespaces></tags>

 

Ref- http://mspbox.blogspot.com/2014/09/limit-tags-selection-to-certian-number.html

 
kautuk_sahni
Community Manager
Community Manager
June 7, 2016

Hi Please have a look at this old post:- https://forums.adobe.com/thread/1175413

//

<locationTag jcr:primaryType="cq:Widget" allowBlank="{Boolean}false"  
       cls="cq-propsdialog-tags" fieldLabel="Campus Location"  
       fieldDescription="Specify a campus location" name="./locationID/cq:tags"  
                                                  xtype="tags">  
       <namespaces jcr:primaryType="cq:WidgetCollection">  
            <ns1 jcr:primaryType="nt:unstructured" maximum="1"  name="campuses" />  
       </namespaces>  
  </locationTag>  

 

The configuration (if used in the complex format) actually expects a nested structure of JCR nodes. Therefore, in my dialog.xml I needed an additional node:

<tags
  jcr:primaryType="cq:Widget"
  allowBlank="true"
  fieldLabel="Tags"
  name="./tags"
  xtype="tags">
    <namespaces jcr:primaryType="cq:WidgetCollection">
        <topics jcr:primaryType="nt:unstructured" maximum="1" name="topics" />
    </namespaces>
</tags>

Link:- http://stackoverflow.com/questions/37661502/trouble-limiting-the-number-of-tags-in-a-taginputfield

 

I hope this would help you.

Thanks and Regards

Kautuk Sahni

Kautuk Sahni
askdctmAuthor
Level 9
June 7, 2016

Hi Kunal/Kautuk,

Thank you for your reply.

#1]Currently I want to limit the tags selected in that field to 3, irrespective of the namespaces they belong to. Tried with the below, but its not working and the tag field shows up blank.

<tags
                        jcr:primaryType="cq:Widget"
                        allowBlank="false"
                        cls="cq-propsdialog-tags"
                        fieldLabel="Tags"
                        name="./cq:tags"
                        xtype="tags">
                        <namespaces jcr:primaryType="cq:WidgetCollection">
                            <mycrxsample
                                jcr:primaryType="nt:unstructured"
                                maximum="3"
                                name="mycrxsample"/>
                        </namespaces>
                    </tags>

askdctmAuthor
Level 9
June 9, 2016

Hi All,

I am still not able to get this to work.

I want to restrict the total number of tags to 3 in my component tag field, irrespective of the namespaces they are coming from.

Any additional thoughts/snippet on this will be helpful.

smacdonald2008
Level 10
June 9, 2016

The Tags Xtype does not support a field that you can set to limit the number of tags you can find:

https://docs.adobe.com/docs/en/cq/5-6/widgets-api/index.html?class=CQ.tagging.TagInputField

You will have to write custom xtype using this data type. You can add custom logic to control the number of tags selected. 

Fort example -- you can use the addtag event to handle a counter. Each time a tag is selected - you can increment an index that controls the number of tags you can add. This is the only way i can see. 

Now if you  to query tags - use backend Java logic to query the tags selected by the dialog. You can use the tag manager API: 

https://helpx.adobe.com/experience-manager/using/customtags1.html

askdctmAuthor
Level 9
June 10, 2016

Hi Scott,

Thank you for your reply.

Since the article in http://mspbox.blogspot.com/2014/09/limit-tags-selection-to-certian-number.html mentioned about restricting tags in AEM 6.0, thought of trying on the similar lines. 

Also, not sure how is it working , based on the article. Thought can tweak it to meet my objective.

kautuk_sahni
Community Manager
Community Manager
June 10, 2016

I have asked internally, i will share their response soon.

Thanks and Regards

Kautuk Sahni

Kautuk Sahni
askdctmAuthor
Level 9
June 10, 2016

Hi Kautuk,

Thank you for your reply.

askdctmAuthor
Level 9
June 11, 2016

Hi All,

If anyone has implemented such a use case, it would be helpful if you can share snippet on this. 

askdctmAuthorAccepted solution
Level 9
June 12, 2016

Hi All, 

Tried writing a listener making use of addtag() event in Tagfield, but it is failing in all scenarios except one. Basically, is of no use in real world-scenarios.

Any snippet/reference would be helpful.