Expand my Community achievements bar.

SOLVED

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

Avatar

Level 9

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.

1 Accepted Solution

Avatar

Correct answer by
Level 9

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.

View solution in original post

13 Replies

Avatar

Employee Advisor
<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

 

Avatar

Administrator

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

Avatar

Level 9

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>

Avatar

Level 9

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.

Avatar

Level 10

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

Avatar

Level 9

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.

Avatar

Administrator

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

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

Avatar

Level 9

Hi Kautuk,

Thank you for your reply.

Avatar

Level 9

Hi All,

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

Avatar

Correct answer by
Level 9

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.

Avatar

Administrator

Hi

The internal team has said that you need to write a custom validator to do the needful.

Reference article shared are:-

Link 1:- http://experience-aem.blogspot.in/2016/06/aem-62-touch-ui-validator-for-restricting-tag-count-dialog... [Touch UI]

Link 2:- http://experience-aem.blogspot.in/2016/06/aem-61-classic-ui-limit-number-of-tags-selected-xtype-tags... [Classic UI]

I hope this would help you.

 

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

Avatar

Level 9

Hi Kautuk,

Phewwww. At last able to get it to work. Thanks a ton :)

Avatar

Administrator

askdctm wrote...

Hi Kautuk,

Phewwww. At last able to get it to work. Thanks a ton :)

 

Excellent!!

Please share a solution with small code for communities benefit.

 

Thanks and Regards

Kautuk Sahni  



Kautuk Sahni