Meet us at Sitecore Symposium 2024 and Discover New Ways to Enhance Your Dynamics Experience. Book a Meeting

Let’s Talk

We would love to hear from you. Want to know more about
our services or have any questions? Say Hi!

How to set up custom validation for the field Tree List in Sitecore?

May 19, 2023
How to set up custom validation for the field Tree List in Sitecore?
Juanita Xavier
Juanita Xavier
Project Manager
how-to-set-up-custom-validation-for-the-field-tree-list-in-sitecore

A Treelist is a combination of multi-list and tree fields. In this blog, we will explore how you can set up a custom validation for the field Treelist in Sitecore.

In general, "Treelist" type field allows the users to select n number of selection. But in some case, requirement will come to select two or three items only.

Please follow the below steps to achieve treelist field validation.

To achieve that go to your Template. Then select treelist field item.

how-to-set-up-custom-validation-for-the-field-tree-list-in-sitecore-1

Go to Validation field and put the regex "^({[^}]+}\|?){0,1}$" in the field.

how-to-set-up-custom-validation-for-the-field-tree-list-in-sitecore-2

In my case, this expression is limiting the selection to 1 only. But you can change any number you want in regex.

Now there is one problem that will occur if they use only regex. The user will not get a proper error message. The message will look like this.

how-to-set-up-custom-validation-for-the-field-tree-list-in-sitecore-3

This error message will confuse the user. To customize the message user, must put his customize message in the Validation Text field.

how-to-set-up-custom-validation-for-the-field-tree-list-in-sitecore-4

Now the error message will change while the user saves the item.

how-to-set-up-custom-validation-for-the-field-tree-list-in-sitecore-5

This way we can control the selection limit in Treelist type fields.

With the above given steps, you can set up custom validation for Sitecore Treelist.


YOU MAY ALSO LIKE