Sitecore Droptree won't exclude items
Asked Answered
B

1

8

I'm working on a Sitecore 8.1 installation. I'm trying to use a droptree field to allow content editors to pick one item (data template A) from a tree of items. Each item that's a valid selection is guaranteed to have one or more child items of a different data template (data template B). According to the documentation, this should be easy to do: just set the source to either a parameterized datasource:

Datasource=/sitecore/Media Library/Images/Folder&IncludeTemplatesForDisplay=Data Template A

or a query:

query:/sitecore/Media Library/Images/Folder/*[@@templatename='Data Template A']

For some reason, though, the field seems to ignore anything but the path. It will display the correct portion of the tree, but shows all items (including those of Data Template B) and allows them to be selected. I've tried various permutations of [Exclude|Include]TemplatesFor[Selection|Display], none of which has proven effective. I've also tried excluding B from the query using [@@templatename!='Data Template B'] or both approaches with templateid.

I haven't been able to find a lot of information about this, other than the occasional vague reference to droptree not honoring exclusions. The common solution seems to be using a TreeList with a regex validation to limit it to one selection. This approach is adequate, but not really what I'd prefer: the TreeList UI is a bit weird for single selection, and I'd prefer to just not allow a user to select multiple items at all rather than throwing a validation error when they do.

There are a few other fields I could use that honor the exclusions but don't present a tree view: again, serviceable but not idea, as there could potentially be a lot of items here and the tree view provides the user with some helpful context.

I could probably write a new field type that mimics the Droptree but actually honors the exclusion--and I'm stubborn enough that this may be the route I take--but I wanted to check first to make sure I wasn't just missing something. So that's the question: anyone know of a way to make a Droptree honor either ExcludeTemplatesForSelection/Display or filtering by query before I go ahead and write my own?

Baptlsta answered 1/3, 2016 at 21:42 Comment(0)
S
9

Sitecore DropTree field does not support IncludeTemplatesForSelection or IncludeTemplatesForDisplay parameters.

They work only with Treelist, TreelistEx and Mulitlist fields.

What you can use is FilteredTree field type created by Richard Cabral.

You can find it from git here: Filtered Tree by Richard Cabral at github.

Swor answered 2/3, 2016 at 6:24 Comment(2)
Working on implementing this, but a couple of quick notes for anyone who follows after: 1. It also requires this: github.com/sitecorerick/spark-sitecore-client/blob/master/… 2. I added the using TreeNode = Sitecore.Web.UI.HtmlControls.TreeNode to the using statements.Baptlsta
Can now confirm that this works. The only slight issue is that you can't access the tree view through Sitecore Rocks, but that's only an annoyance for me, not the content editors.Baptlsta

© 2022 - 2024 — McMap. All rights reserved.