Setting the value of HierarchicalTaxonField

Posted by Community Admin on 04-Aug-2018 20:26

Setting the value of HierarchicalTaxonField

All Replies

Posted by Community Admin on 27-Sep-2013 00:00

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?

Posted by Community Admin on 02-Oct-2013 00:00

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

Posted by Community Admin on 02-Oct-2013 00:00

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.

This thread is closed