Level: 200
 

Controlling items in a selection field

Image of tools

Treelists are great controls for letting the editors point out a list of items.

For example when choosing which spots to show in a spot column. But when you have a lot of different spots and not all of them fits into the spot column populated by the field, you want to make sure that editors don't choose the wrong spots.

The best thing would be that editors didn't even have the possibility to select the wrong spots in the treelist.

Written by: Jimmi Lyhne Andersen
Sat, Jun 27 2009


 

Scenario

The scenario is the following.

We have three different spottypes in the website. All the spots is placed in a global folder named ”Spots”. In this folder each spot type has its own folder, with the possibility to add more folders of the same type.

 

 

On the website we have a spot column to the right. This column is not wide enough to contain a link spot. And we don't want the editor to add a link spot to this column by mistake.
We could solve this issue by writing code that made sure that spots of the wrong type is not shown in this column. But it turns out that this approach is not necessary.

By using the source property of the RightSpots field, we can make sure that the editor never chooses spots of the wrong type.

Setting the source property

The source property is set on the template

 

 

There are several way to do this. In the following I will describe a couple of them.


As we do not want to allow editors to add link spots to this field, the editor should only be able to choose items of type NewsSpot and TextSpot. They should of course not be able to select item of type NewsSpotFolder or TextSpotFolder.


So we insert the following datasource into the source property.
Datasource=/sitecore/content/Spots
&IncludeTemplatesForDisplay=TextSpotFolder,TextSpot,NewsSpotFolder,NewsSpot
&IncludeTemplatesForSelection=NewsSpot,TextSpot

The treelist now looks like the following picture.

 

 

It is only possible to select items of type NewsSpot and TextSpot. That means that the editor can not select a spot folder by accident.

 

It would also be possible to do this the other way around by excluding templates instead of including them.


In that case the property would look like this.
Datasource=/sitecore/content/Spots
&ExcludeTemplatesForDisplay=LinkSpotFolder
&IncludeTemplatesForSelection=NewsSpot,TextSpot


Please observe that we still need to include IncludeTemplatesForSelection to disable the editor from choosing spot folders.

The list of parameters are

  • DataSource
  • DatabaseName
  • IncludeTemplatesForSelection
  • ExcludeTemplatesForSelection
  • IncludeTemplatesForDisplay
  • ExcludeTemplatesForDisplay
  • IncludeItemsForDisplay
  • ExcludeItemsForDisplay
  • AllowMultipleSelection

 

 

 

 

 

 

 

Please rate this article


5 rates / 4,4 avg.

  • Picture of Jimmi Lyhne Andersen

    About the author:

    Jimmi Lyhne Andersen

    Jimmi Lyhne Andersen is the co-founder of LearnSitecore, and is a partner at Inmento Solutions.
    Jimmi has been lead developer and architect on several large public websites with 200+ editors, and is therefore focused on usability and accessibility.
    Jimmi is a certified Sitecore developer and a Microsoft Certified Professional Developer (MCPD).
    He has a bachelors degree in Computer Science and in Mathematics from the University of Copenhagen.

     

5 responses to "Controlling items in a selection field"

Excellent article, which taught me something new. :)

Regarding your site, you might want to look into some fashion of text breaking/wrapping functionality. Currently, extremely long words or text blocks without spaces break the layout by extruding past the intended visual boundary (e.g., the Source field values in the article above.)
Posted: Thursday, July 09, 2009 6:56 PM
Hi Morten.

Thank you for commenting on the article. I will try to be more careful when writing long lines of code in the future. I have inserted some breaks in the article and hope it's more readable now.

Posted: Thursday, July 09, 2009 9:07 PM
Great article, had an idea this was possible but couldn't find enough documentation.

I can't get AllowMultipleSelection to work - I've tried setting it to False, false and 0 but it still allows multichoice.

Also, any idea if this works on any other field types?
Posted: Tuesday, October 13, 2009 4:39 PM
Hi
Have any of you any experience with extending this fieldtype, so it is easier for the user to find the selected item again.
If a user those an item in a large structure it can be difficult to locate this item again.
So it would be nice if it was possible to display the path to the user.
Also, I thought it would be cool if a link was made from each selection, so it was easy for the user to navigate (and edit) the selected item.
Anyone tried to implement such features?
Posted: Tuesday, November 10, 2009 12:13 PM
Sam
i Have a treelist field in my website and i want to access part of content from all folder under the main folder. Actually i want to pull certain fields from all the items in all folders. Any help , i am new to Sitecore.
Posted: Sunday, March 24, 2013 8:14 PM

Leave a reply


Notify me of follow-up comments via email.
 
 
#nbsp;