Taxon Field Examples

Posted by Community Admin on 03-Aug-2018 21:46

Taxon Field Examples

All Replies

Posted by Community Admin on 29-Nov-2010 00:00

I have been looking for some examples of implementing HierarchicalTaxonField and FlatTaxonField controls into widget designers.  Is there a good reference somewhere?


I have (almost) successfully implemented a HierarchicalTaxonField control but I am tripping on setting the default taxonomy id.

Here is the stack trace:
[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

and here is the code:

<sitefinity:HierarchicalTaxonField ID="sfCategories" runat="server"
    AllowMultipleSelection="true"
    WebServiceUrl="~/Sitefinity/Services/Taxonomies/HierarchicalTaxon.svc"
    BindOnServer="true" DisplayMode="Read" ResourceClassId="ContentResources"
    TaxonomyMetafieldName="Category" ExpandText="ClickToAddCategories"/>

I am able to successfully get the instance of the control from the designer by using a lazy-initializing getter:
        private HierarchicalTaxonField categoryField;
        protected virtual HierarchicalTaxonField CategoryField
        
            get
            
                if (categoryField == null)
                    categoryField = this.Container.GetControl<HierarchicalTaxonField>("sfCategories", true);
                return categoryField;
            
        

But this is where the success ends.  Any thoughts?

Thanks,
Bryan

Posted by Community Admin on 02-Dec-2010 00:00

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);


Kind regards,
Ivan Dimitrov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about 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 24-May-2011 00:00

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(); 
   ,

Posted by Community Admin on 24-May-2011 00:00

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); //
        


Posted by Community Admin on 25-May-2011 00:00

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

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 25-May-2011 00:00

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;
        

Then on using your technique to debug the code i have the following flow, please see comments by each line

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;
   ,

Posted by Community Admin on 25-May-2011 00:00

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

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 04-Feb-2014 00:00

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);
        


This will then set the value correctly in your designer. This should be done in the refreshUI function.

This thread is closed