We are all about adding value to the industry. We provide high-quality and remarkable tech solutions to all our clients across the globe.
The people of Addact are truly unique and we invite you to be a part of our growth journey!
Find out moreWe use cookies to ensure that we give you the best experience on our website. If you continue to use this site, you consent to the use of cookies. privacy policy and cookie policy.
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.
Go to Validation field and put the regex "^({[^}]+}\|?){0,1}$" in the field.
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.
This error message will confuse the user. To customize the message user, must put his customize message in the Validation Text field.
Now the error message will change while the user saves the item.
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.