+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Setting the value of HierarchicalTaxonField

Setting the value of HierarchicalTaxonField

3 posts, 0 answered
  1. Chris
    Chris avatar
    3 posts
    Registered:
    13 Feb 2013
    27 Sep 2013
    Link to this post
    I'm using a HierarchicalTaxonField in a custom module's web ui. I can read the value of it and save it to my db table without any issues, but I cannot bind a value back to it on my edit screen.

    Setting the field's value to any IList<Guid> or TackedList<Guid> on page load does nothing. Literally. I can set the value to a list of guids, and inspecting the value on the very next line shows that it has not changed, as if the setter on the property doesn't exist.

    I can kind of make this work if I set BindOnServer to false, but then I can't read the value back on form submission.

    This seems like it should be trivial to do but I can't find any examples of how to do this. You should be able to use this field on an item's edit screen without any problems, so why is it so difficult?
  2. Pavel Benov
    Pavel Benov avatar
    341 posts
    Registered:
    14 Mar 2016
    02 Oct 2013
    Link to this post
    Hello Chris,

    Try using the item.Organizer.AddTaxa("fieldName", taxonID) in order to associate a taxon with a certain item. Here is a sample that does this with Documents and custom taxonomy.

    LibrariesManager libManager = LibrariesManager.GetManager();
                TaxonomyManager taxManager = TaxonomyManager.GetManager();
                var master = libManager.GetDocuments().Where(d => d.Title == "DocumentTitle" && d.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master).FirstOrDefault();
                var taxon = taxManager.GetTaxa<HierarchicalTaxon>().FirstOrDefault(s => s.Title == "TaxonTitle");
                if (master != null)
                {
                    var temp = libManager.Lifecycle.CheckOut(master) as Document;
                    temp.Organizer.AddTaxa("FieldTitle", taxon.Id);
                    master = libManager.Lifecycle.CheckIn(temp) as Document;
                    libManager.SaveChanges();
                     
                }
     
    I hope this helps.

    Regards,
    Pavel Benov
    Telerik
    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
  3. Chris
    Chris avatar
    3 posts
    Registered:
    13 Feb 2013
    02 Oct 2013 in reply to Pavel Benov
    Link to this post
    Hi Pavel,

    I'm not trying to associate a taxon with an item in this case. I'm trying to set the value of a HierarchicalTaxonField control on the edit page for a custom content type when the page loads.

    TrackedList<Guid> categories = GetCategoriesForItem(); // I'm deserializing Guids from a string here
     
    // categories now contains two guids,
    // categoriesSelector.Value is an empty TrackedList<Guid>
     
    categoriesSelector.Value = categories; // set the value of the control to the saved categories

    After setting that value, categoriesSelector.Value is still empty. The assignment does nothing.
3 posts, 0 answered