Custom field for Events

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

Custom field for Events

All Replies

Posted by Community Admin on 10-Feb-2012 00:00

Hi,
I want to add a combo box to my event as a custom field.I have created a usercontrol which is bound to database table.
it gets added to my event. but due to that field my event data is not getting store.I i remove that field from event, everything is working fine.
Please provide me some code for doing such thing.

Thanks & Regards,

Posted by Community Admin on 14-Feb-2012 00:00

Hi,

 Here's how you can achieve this with our Choice Field:

You can inherit from ChoiceField and modify its Choices collection with the items from your database table. However, you also need to create a Definition and an Element for your custom field. Then, when you register the field, choose the type to be Multiple Choice. Here's how this should look:

The Custom Choice Field class that inherits from ChoiceField 

Copy Code
[FieldDefinitionElement(typeof(CustomChoiceFieldElement))]public classCustomChoiceField : ChoiceField
   
    
   
        public CustomChoiceField()
   
            base()
   
        
   
                 
   
        
   
             
   
        public override Telerik.Sitefinity.Web.UI.Fields.Enums.RenderChoicesAs RenderChoicesAs
   
        
   
            get
   
            
   
                returnTelerik.Sitefinity.Web.UI.Fields.Enums.RenderChoicesAs.DropDown;
   
            
   
            set
   
            
   
                base.RenderChoicesAs = value;
   
            
   
        
   
             
   
        protected override voidInitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
   
        
   
            this.Choices.Clear();
   
            ChoiceItem choiceItem = new ChoiceItem();
   
            choiceItem.Value = "first";
   
            ChoiceItem choiceItem2 = new ChoiceItem();
   
            choiceItem2.Value = "second";
   
     
   
     
   
            this.Choices.Add(choiceItem);
   
            this.Choices.Add(choiceItem2);
   
            base.InitializeControls(container);
   
                 
   
                 
   
                 
   
        
   
        protected override string ScriptDescriptorType
   
        
   
            get
   
            
   
                return typeof(ChoiceField).FullName;
   
            
   
        
   
     
   
    
You can see here that I'm clearing the Choices collection and populating it with new records. This is the place where you can populate the collection with your custom items from the data table.

Also here are the relevant element and definition for the field control: 

Copy Code
class CustomChoiceFieldDefinition : ChoiceFieldDefinition
   
    
   
        public CustomChoiceFieldDefinition() : base()
   
        
                  this.FieldType = typeof(CustomChoiceField);
        
   
     
   
        /// <summary>
   
        /// Initializes a new instance of the <see cref="SimpleImageFieldDefinition"/> class.
   
        /// </summary>
   
        /// <param name="element">The configuration element used to persist the control definition.</param>
   
        public CustomChoiceFieldDefinition(ConfigElement element)
   
            base(element)
   
        
                 this.FieldType = typeof(CustomChoiceField);
        
   
    

Copy Code
class CustomChoiceFieldElement : ChoiceFieldElement
   
    
   
        /// <summary>
   
        /// Initializes a new instance of the <see cref="SimpleImageFieldElement"/> class.
   
        /// </summary>
   
        /// <param name="parent">The parent.</param>
   
        public CustomChoiceFieldElement(ConfigElement parent)
   
            base(parent)
   
        
   
        
   
     
   
             
   
     
   
        /// <summary>
   
        /// Gets an instance of the <see cref="SimpleImageFieldDefinition"/> class.
   
        /// </summary>
   
        /// <returns></returns>
   
        public override DefinitionBase GetDefinition()
   
        
   
            return new CustomChoiceFieldDefinition(this);
   
        
   
    

Hope this helps. 

All the best,
Svetoslav Petsov
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 15-Feb-2012 00:00

Hi,
This works.
Thanks a lot

Posted by Community Admin on 04-Nov-2013 00:00

is this still the correct way to do this? I attempted to follow this, created a custom field just as shown, and I added it to the Documents type no problem, it even shows all the custom items.

However, when I publish, I get this error: 

500 (There was an error deserializing the object of type Telerik.Sitefinity.Web.Services.ContentItemContext`1[[Telerik.Sitefinity.Libraries.Model.Document, Telerik.Sitefinity.Model, Version=6.1.4700.0, Culture=neutral, PublicKeyToken=b28c218413bdf563]]. End element 'MyChoices' from namespace '' expected. Found element 'item' from namespace ''.)

What am I missing?

Posted by Community Admin on 15-Apr-2014 00:00

Did you ever get an answer on this?  I am trying to add a custom field for BlogPosts that exhibits the same issue when I try to publish.  The Thunder generated control works just find as a custom field for News though.

 

This thread is closed