Category Archive for "cq:tags"

Limiting allowed cq:tags-path within namespaces

13.01.2015
Christoph Thommen

A common issue when working with CQ tags is the lack of possibility to limit the user entering only specific trees of tags within a namespace in a specific TagInputField.

Example

We have a tag structure like:

  • /etc/tags/search/keyword/…
  • /etc/tags/search/client/…
  • /etc/tags/search/…/…

Now we want the user to enter keywords (and only keywords) in the page property field “Keywords”.

The issue we’re no facing is, that in CQ only allowed namespaces can be limited, but not paths inside a namespace.

 

To solve this, the following listener attached to the TagInputField in the dialog.xml might help:

This listener is fired each time a tag is added to the TagInputField. The listener checks if the tag is located inside the desired path (in our case “/keyword”). If not, it will be removed again immediately.

 

This is a really easy way to restrict TagInputField to certain tag paths.