Limit an Umbraco Tag Picker

Tags Property Editor

Have you ever needed to limit the number of tags an editor can pick in the backoffice when using a Tag Property Editor? 

Below is a demo of what I am referring to

The out of the box, comes with Umbraco, Tags Property Editor :

Property Editor

This is the tags property editor in use on a document type: 

Tags Property Editor Demo

Each tag is added in to a json blob and the editor can keep on adding as many as they want. This has two issues in the scenario I was working on, 1. I don't want the editor to be able to add tags on this specific document type. 2. I need the editor to only be able to select one tag from the json blob.

As you can see in the property editor settings above, there isn't an option to limit how many tags are added. 

How to solve this issue?

My first thought was to write a NotificationHandler that when the editor saves or publishes a page, then I check the property editor and see how many items are added, but this isn't a nice user experience and it would still allow an editor to add more tags to the json storage.

I spoke with a work mate about this and he suggested we look at what is possible with Contentment. This was when we found that we could use Contentment Data List property editor and then when setting up the Data List, use the Umbraco Tags as the data source. You can also put a maximum number of items allowed to be picked. 


As you can see from the demo above, this now means I can set one item to be picked, remove it, add another, however I can't add multiples. It uses the json blob of all the tags (which are set on a different area of the site). Perfect! 

Thanks Luke for pointing me to this. 

Published on : 12 March 2024