Taxon Field Examples
I have been looking for some examples of implementing HierarchicalTaxonField and FlatTaxonField controls into widget designers. Is there a good reference somewhere?
[NullReferenceException: Object reference not set to an instance of an object.] Telerik.Sitefinity.Taxonomies.TaxonomyManager.GetTaxonomy(Guid id) +20 Telerik.Sitefinity.Web.UI.Fields.TaxonField.get_Taxonomy() +124 Telerik.Sitefinity.Web.UI.Fields.HierarchicalTaxonField.InitializeControls(GenericContainer container) +187 Telerik.Sitefinity.Web.UI.SimpleView.CreateChildControls() +81 System.Web.UI.Control.EnsureChildControls() +181 System.Web.UI.Control.PreRenderRecursiveInternal() +59 System.Web.UI.Control.PreRenderRecursiveInternal() +221 System.Web.UI.Control.PreRenderRecursiveInternal() +221 System.Web.UI.Control.PreRenderRecursiveInternal() +221 System.Web.UI.Control.PreRenderRecursiveInternal() +221 System.Web.UI.Control.PreRenderRecursiveInternal() +221 System.Web.UI.Control.PreRenderRecursiveInternal() +221 System.Web.UI.Control.PreRenderRecursiveInternal() +221 System.Web.UI.Control.PreRenderRecursiveInternal() +221 System.Web.UI.Control.PreRenderRecursiveInternal() +221 System.Web.UI.Control.PreRenderRecursiveInternal() +221 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4184<sitefinity:HierarchicalTaxonField ID="sfCategories" runat="server" AllowMultipleSelection="true" WebServiceUrl="~/Sitefinity/Services/Taxonomies/HierarchicalTaxon.svc" BindOnServer="true" DisplayMode="Read" ResourceClassId="ContentResources" TaxonomyMetafieldName="Category" ExpandText="ClickToAddCategories"/>Hello Bryan,
You need to supply TaxonomyId (TaxonomyId="E5CD6D69-1543-427b-AD62-688A99F5E7D4"). Currently the control calls GetTaxonomy but you do not pass any value which results in a error.
Also you use the control in Read mode and it would be better just to get the categories through the API.
sample
var taxaList = new List<ITaxon>();var manager = TaxonomyManager.GetManager();var categoriesTaxonomy = manager.GetTaxonomy(TaxonomyManager.CategoriesTaxonomyId);taxaList.AddRange(categoriesTaxonomy.Taxa);Hi,
I am also trying to use this Field Control and am almost there (i hope)
I have implemented the control and all opens fine in the designer and i can navigate through the departments, however i am struggling to select the currently selected Category and also return the Selected Value, any ideas, i think the problem is in my code below
refreshUI: function () this._refreshing = true; var categoryID = this.get_controlData().CategoryID; if (categoryID) this.get_Selector().set_value(categoryID); this._refreshing = false; , applyChanges: function () this.get_controlData().CategoryID = this.get_Selector().get_value(); ,I have progressed the issue further and narrowed it down to this line, for some reason even though categoryID is a valid Guid it is being shortened to just 1 character by this method thus becoming an invalid Guid, no idea why?
var categoryID = this.get_controlData().CategoryID; if (categoryID) this.get_Selector().set_value(categoryID); // Hi Anthony,
This line
var categoryID = this.get_controlData().CategoryID;
gets the value of the property that is in the control . Is this value of type string or Guid?
I attached a short video that illustrates returning the correct value.
Kind regards,
Ivan Dimitrov
the Telerik team
Hi Ivan,
The value in the control is Guid as seen here
private Guid _categoryID = new Guid("f37551ea-0d7d-44d8-b7b1-1d95ca7f0b44"); public Guid CategoryID get return this._categoryID; set this._categoryID = value; refreshUI: function () //this._refreshing = true; var categoryID = this.get_controlData().CategoryID; // This gets the current value of PageId from our control (in PageSelector.cs) alert(categoryID); // ALERT: returns f37551ea-0d7d-44d8-b7b1-1d95ca7f0b44 if (categoryID) this.get_Selector().set_value(categoryID); // Here we set the current page for our PageField control (if its already set) // ALERT: returns error Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). // on clicking advanced i can see the CategoryID value has been changed to a single digit 'f'???? //this._refreshing = false; ,Hi Anthony,
I am not able to replicate this issue. If you want you can open a support request and attache your project.
Greetings,
Ivan Dimitrov
the Telerik team
just for anyone that comes across the same issue in trying to set the selected value from a hierarchical taxon selector, you need to pass an array of GUIDs and not a single GUID as below:
var controlData = this._propertyEditor.get_control().Settings; if (controlData.ItineraryId && controlData.ItineraryId != '00000000-0000-0000-0000-000000000000') var selectedNode = '' + controlData.ItineraryId.toString(); var selectedNodes = new Array(); selectedNodes.push(selectedNode); this.get_ItinerarySelector().set_value(selectedNodes);