Backend Category Selector

Posted by Community Admin on 04-Aug-2018 16:08

Backend Category Selector

All Replies

Posted by Community Admin on 09-Aug-2011 00:00

Hello-

I'm working on functionality to get the list of currently selected categories for a content item (blogs in my case).  I have written a custom field that has a drop down list but I want to populate it on the fly with the current selected categories.  The goal being to mark one category logically as the "primary" category for this item.

Here is what I've tried so far:

1) I've tried calling the Telerik.Sitefinity.Web.UI.Fields.HierarchicalTaxonField javascript object in various ways to eitehr add a new event to the selection done delegate, or to get the list of selected taxa with no luck.

2) I've tried using jQuery to get a list of all of the sub-items in the sfCategoriesList class, but jQuery for some reason cannot see these elements, even though I can inspect them through the DOM.


I have been able to use the jQuery live syntax to bind an event to the category done button like this:

jQuery(".sfLinkBtnIn:contains('Done')").live('click', function ()
    // custom logic here
    console.log(jQuery(".sfCategoriesList").size());  // always returns 0
);


Any help or recommendations would be appreciated.

Thanks,

-Thomas

Posted by Community Admin on 11-Aug-2011 00:00

Hi Thomas Weidman,

HierarchicalTaxonField provides two functions:
add_taxonAdded - This function allows other objects to subscribe to the taxonAdded event of the taxon field.
add_taxonRemoved -  This function allows other objects to subscribe to the taxonRemoved event of the taxon field.

So, if you have access to HierarchicalTaxonField object, you could use the functions above to subscribe for taxonAdded and taxonRemoved events and add/remove items to/from your drop down on fly. For example:

field.add_taxonAdded(addTaxon);
 
function addTaxon(sender, args)
 //custom code

args contains the Id and the Title of the newly added taxon.

As for getting the currently selected categories, you could do it on a client using the same service we use in HierarchicalTaxonField: ~/Sitefinity/Services/Taxonomies/HierarchicalTaxon.svc/batchpath/. You need to use InvokePut method of the Telerik.Sitefinity.Data.ClientManager() to call the service.

I hope this helps.

Kind regards,
Pepi
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 11-Aug-2011 00:00

Pepi-

Hello.Thank you for the reply you've got me looking in the correct direction now.  One question, how to I invoke the add_taxonAdded method?  The field I'm building is using the "ChoiceField" format so I can have it display as a select list.  I used firebug and tried looking at the following objects:

Telerik.Sitefinity.Web.UI.Fields.TaxonField
Telerik.Sitefinity.Web.UI.Fields.HierarchicalTaxonField

Both return an undefined, so I'm missing something to allow this code to access the function to subscribe to the events you mentioned.

Thanks,

-Thomas

Posted by Community Admin on 14-Aug-2011 00:00

Pepi-

Thanks for your reply, I figured it out.

-Thomas

Posted by Community Admin on 15-Aug-2011 00:00

Hi Thomas,

Could you please share the solution with others who may follow the forum post?

Thank you!

Kind regards,
Veronica Milcheva
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed