More in this section

Forums / Developing with Sitefinity / Backend Category Selector

Backend Category Selector

5 posts, 1 answered
  1. Thomas Weidman
    Thomas Weidman avatar
    38 posts
    Registered:
    19 Apr 2004
    09 Aug 2011
    Link to this post
    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
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    11 Aug 2011
    Link to this post
    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
    Answered
  3. Thomas Weidman
    Thomas Weidman avatar
    38 posts
    Registered:
    19 Apr 2004
    11 Aug 2011
    Link to this post
    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
  4. Thomas Weidman
    Thomas Weidman avatar
    38 posts
    Registered:
    19 Apr 2004
    14 Aug 2011
    Link to this post
    Pepi-

    Thanks for your reply, I figured it out.

    -Thomas
  5. Veronica
    Veronica avatar
    125 posts
    Registered:
    30 Jan 2015
    15 Aug 2011
    Link to this post
    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
5 posts, 1 answered