6 YEARS AGO

Enabling the Multiple Category Selector in Web Parts

If there is one thing in Kentico that I repeatedly forget, it's the fact that the Multiple Category Selector form control by default only works in documents/pages. Fortunately, it is quite easy to tweak the control to be used within web parts/widgets. This post highlights the code to tweak and provides a nuget package for you to play with.

Before I start, please let me state that I would never recommend changing the Kentico source code. So please use below steps as reference for the things to adjust in a copy of the default Multiple categories selector form control.

First thing to do is enable the "Multiple categories selector" form control to be used in web parts:

Enable form control to be used in web parts

Remember: the multiple categories selector is intended to be only used within page types and it won't work in other places if you don't make additional changes.

Next change the following code in "CMSModules\Content\FormControls\Categories\CategorySelector.ascx":
<cms:UniSelector ID="selectCategory" runat="server" ReturnColumnName="CategoryName" ObjectType="cms.categorylist" ResourcePrefix="categoryselector" OrderBy="CategoryNamePath"             AdditionalColumns="CategoryNamePath,CategoryEnabled" SelectionMode="SingleTextBox" AllowEmpty="true" IsLiveSite="false" AllowEditTextBox="true" DisabledItems="personal" />
to:
<cms:UniSelector ID="selectCategory" runat="server" ReturnColumnName="CategoryID" ObjectType="cms.categorylist" ResourcePrefix="categoryselector" OrderBy="CategoryNamePath"            AdditionalColumns="CategoryNamePath,CategoryEnabled" SelectionMode="Multiple" AllowEmpty="false" IsLiveSite="false" />
Again, the best way to approach this is to copy the control and create your custom form control. And that's it! 

As promised please find the link to a nuget package containing the custom multiple categories selector form control here.

If you wish that this control would be out-of-the-box available then please cast your vote at Kentico Ideas.