1

I have a Categories Item and Each category has Sub categories

- Category 1 
       - Sub Category 1
       - Sub Category 1
       - Sub Category 1

- Category 2
       - Sub Category 2
       - Sub Category 2
       - Sub Category 2

- Category 3 
       - Sub Category 3
       - Sub Category 3
       - Sub Category 3

I have Two MultiLists fields

- Category
- SubCategory

The query for Category is

query:./ancestor-or-self::*[@@templatename='Site']/Components/Categories Folder//*[@@templateid='{11170316-18F1-43A3-9FC8-CAEAA0134389}']/*

This query is picking

  -Category1
  -Category2
  -Category3

in the multilist which is fine.

I want to get SubCategory to be filled based on the Category MultiList selection.

For example if Category2 is selected in the Category multilist then SubCategory MultiList should have

SubCategory2
SubCategory2
SubCategory2

in the multilist.

Has anyone done something similar ?. Any help or suggestion would be appreciated

Thanks in advance

1
  • I'm not sure it's possible without creating a new field type from scratch. One issue you'll have to overcome is that the fields are rendered when the item is selected, so it wouldn't know to change when you select a different Category item. Commented Mar 6, 2019 at 12:39

1 Answer 1

0

I am not sure if this can be done, and I don't think it's a good idea to make one field dependent on the other. Like what Dan mentioned, there would probably be issues around updating the 2 different fields at different scenarios.

I suggest you use a tree list field type for this and utilise IncludeTemplatesForSelection option to limit users to choose only subcategories items types.

DataSource=/sitecore/content/home/CategoryRoot&AllowMultipleSelection=yes&IncludeTemplatesForSelection=Subcategory

If you need to force users to be able to only select subcategories from the same category, then you can create a custom field validator that checks if all selections belongs to the same parent category item.

It is definitely much easier than writing your own custom field and personally I think it is easier for the user to see all available category options at a glance within a single field.

There are some pretty good links that talks about treelist and custom validators that you can reference

http://firebreaksice.com/tame-your-sitecore-treelists/

https://www.habaneroconsulting.com/stories/insights/2016/creating-a-custom-field-validator-in-sitecore

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.