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

, , , , , , , ,

  1. #1 by Dan on June 5, 2015 - 2:36 pm

    Thanks for this. It’s an interesting work around that you are validating if it is a GUID. I guess if you have a one or empty validation, you could make sure there are no pipes ‘|’, as the pipe is the delimiter between GUIDS when there are multiple items.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: