Boolean field in custom module

Posted by Community Admin on 05-Aug-2018 17:20

Boolean field in custom module

All Replies

Posted by Community Admin on 22-Feb-2011 00:00

Hello,

I have a boolean property myField.

In the insert/edit form, I placed a choicefielddefinitionelement. I create a new item, checked the checkbox and save. When I edit an item, the checkbox is not selected but in the database, the value is well saved (set to 1).

Here is my code:

private bool myField;
  
 [FieldAlias("myField")]
        [DataMember]
        public bool MyField
        
            get return this.myField;
            set this.myField= value;
        
  
var myFieldElement = new ChoiceFieldElement(mainSection.Fields)
            
                ID = "myFieldElementControl",
                FieldType = typeof(ChoiceField),
                DataFieldName = "MyField",
                DisplayMode = displayMode,
                MutuallyExclusive = false,
                RenderChoiceAs = RenderChoicesAs.SingleCheckBox,
                CssClass = "sfCheckBox sfFormSeparator",
                Title = (displayMode == FieldDisplayMode.Read) ? "Active?" : string.Empty,
                Description = "Description of myFieldElement",
                WrapperTag = HtmlTextWriterTag.Li
            ;
            ChoiceElement item = new ChoiceElement(myFieldElement.ChoicesConfig)
            
                Text = "Active?"
            ;
  
            myFieldElement.ChoicesConfig.Add(item);
  
            mainSection.Fields.Add(myFieldElement);

Do you have any idea of what could cause this issue?

Jocelyn

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

Hi jocelyn payneau,

You need to copy the specific property in the manager Copy method (this is needed for the purposes of the Content Lifecycle):

Copy Code
public void Copy(ProductItem source, ProductItem destination)
    ...
    destination.MyField = source.MyField;

Let us know if this solves the described issue.

Best wishes,
Pepi
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!

This thread is closed