Monday, March 24, 2008

TreeList Field with a Single Selection


The "TreeList" type of a field in Sitecore is quite handy. It supports multiple dynamic parameters and even unofficially supports query. This is sweet, but sometimes you need a single selection with all the features above which is not provided by such single selection lookup types as "Tree", "Lookup", etc.

The simplest way to get past this requirement is simply rely on the "TreeList" type and set a RegExp to validate a selection of a single GUID. In order to do that, locate the field in the Template Manager and set the "Validation" field to ^[{|\(]?[0-9a-fA-F]{8}[-]?([0-9a-fA-F]{4}[-]?){3}[0-9a-fA-F]{12}[\)|}]?$

Don't forget to add a friendly warning to the "ValidationText" field.

Easy!

0 comments: