Restrict Multilist with search to a single item

Sitecore 7 comes with the multiselect with search field type which is really handy when it comes to datasource locations with a large number of items, and also for data sources which are item buckets, since navigating through the folder structure within an item bucket can definitely be quite daunting.

I am using sitecore 7.2 and came across the need to allow the content author to select a single item from a large bucket of items.
You can ofcourse opt for creating custom fields, but the easiest way to add this constraint turned out to be adding a suitable validation regex on the intended field:

^{[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}\}$

You could add the intended message to the content author as well:
2014-10-27_015918

Now, on save, the validation message will be triggered:
2014-10-27_020243

If you are using glass mapper, in your custom model (will work with auto map too), you can now have a single corresponding glass object as opposed to having an IEnumerable collection.

Advertisements