Boolean field in custom module
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);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):
public void Copy(ProductItem source, ProductItem destination) ... destination.MyField = source.MyField;