AllowComments field appears 3 times
Hi,
I changed the productsmodule to serve as a companymodule.
All worked fine, until I started to create resources for the dutch language.
I got some errors on not to add multiple items in a SingeCheckBox item.
Now the insert/edit screen is working again (for some reason??) and I see 3 times the 'AllowComments' checkbox.
This is the code for adding this box:
var allowCommentsFieldElement = new ChoiceFieldElement(moreOptionsSection.Fields) ID = "allowCommentsField", Title = (displayMode == FieldDisplayMode.Read) ? "AllowComments" : string.Empty, DataFieldName = "AllowComments", DisplayMode = displayMode, RenderChoiceAs = RenderChoicesAs.SingleCheckBox, CssClass = "sfCheckBox sfFormSeparator", WrapperTag = HtmlTextWriterTag.Li, ResourceClassId = typeof(CompaniesResources).Name ; allowCommentsFieldElement.ChoicesConfig.Add( new ChoiceElement(allowCommentsFieldElement.ChoicesConfig) Text = Res.Get(typeof(CompaniesResources).Name, "AllowComments") ); moreOptionsSection.Fields.Add(allowCommentsFieldElement); detailView.Sections.Add(moreOptionsSection);I'm getting the same error when I add a custom field to the blogsmodule. I added a field that is a Yes / No (boolean).
The error is below:
01.[ArgumentException: When RenderChoiceAs is set to SingleCheckBox, there should be only one ChoiceItem in the collection]02. Telerik.Sitefinity.Web.UI.Fields.ChoiceField.InitializeControls(GenericContainer container) +63203. Telerik.Sitefinity.Web.UI.SimpleView.CreateChildControls() +5804. System.Web.UI.Control.EnsureChildControls() +10205. System.Web.UI.Control.PreRenderRecursiveInternal() +4206. System.Web.UI.Control.PreRenderRecursiveInternal() +17507. System.Web.UI.Control.PreRenderRecursiveInternal() +17508. System.Web.UI.Control.PreRenderRecursiveInternal() +17509. System.Web.UI.Control.PreRenderRecursiveInternal() +17510. System.Web.UI.Control.PreRenderRecursiveInternal() +17511. System.Web.UI.Control.PreRenderRecursiveInternal() +17512. System.Web.UI.Control.PreRenderRecursiveInternal() +17513. System.Web.UI.Control.PreRenderRecursiveInternal() +17514. System.Web.UI.Control.PreRenderRecursiveInternal() +17515. System.Web.UI.Control.PreRenderRecursiveInternal() +17516. System.Web.UI.Control.PreRenderRecursiveInternal() +17517. System.Web.UI.Control.PreRenderRecursiveInternal() +17518. System.Web.UI.Control.PreRenderRecursiveInternal() +17519. System.Web.UI.Control.PreRenderRecursiveInternal() +17520. System.Web.UI.Control.PreRenderRecursiveInternal() +17521. System.Web.UI.Control.PreRenderRecursiveInternal() +17522. System.Web.UI.Control.PreRenderRecursiveInternal() +17523. System.Web.UI.Control.PreRenderRecursiveInternal() +17524. System.Web.UI.Control.PreRenderRecursiveInternal() +17525. System.Web.UI.Control.PreRenderRecursiveInternal() +17526. System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496Hi Daniel,
Can you past the moreOptionsSection and all definition elements in it?
All the best,
Ivan Dimitrov
the Telerik team
Hi,
Because I'm not having much time to dive deep into the problems I'm facing (unfortunately) I recreated the project. I see now that the 'AllowComments' is appearing one time in my custom module.
Anyway, this is the code for the moreOptions section
#region More options section var moreOptionsSection = new ContentViewSectionElement(detailView.Sections) Name = "MoreOptionsSection", Title = "MoreOptionsURL", ResourceClassId = typeof(CompaniesResources).Name, CssClass = "sfExpandableForm", ExpandableDefinitionConfig = Expanded = false ; if (displayMode == FieldDisplayMode.Write) var urlName = new MirrorTextFieldElement(moreOptionsSection.Fields) Title = Res.Get<CompaniesResources>().UrlName, ID = "urlName", MirroredControlId = titleField.ID, DataFieldName = "UrlName", DisplayMode = displayMode, RegularExpressionFilter = DefinitionsHelper.UrlRegularExpressionFilter, WrapperTag = HtmlTextWriterTag.Li, ReplaceWith = "-" ; var validationDef = new ValidatorDefinitionElement(urlName) Required = true, MessageCssClass = "sfError", RequiredViolationMessage = Res.Get<CompaniesResources>().UrlNameCannotBeEmpty, RegularExpression = DefinitionsHelper.UrlRegularExpressionFilterForValidator, RegularExpressionViolationMessage = Res.Get<PageResources>().UrlNameInvalidSymbols ; urlName.ValidatorConfig = validationDef; moreOptionsSection.Fields.Add(urlName); var allowCommentsFieldElement = new ChoiceFieldElement(moreOptionsSection.Fields) ID = "allowCommentsField", Title = (displayMode == FieldDisplayMode.Read) ? "AllowComments" : string.Empty, DataFieldName = "AllowComments", DisplayMode = displayMode, RenderChoiceAs = RenderChoicesAs.SingleCheckBox, CssClass = "sfCheckBox sfFormSeparator", WrapperTag = HtmlTextWriterTag.Li, ResourceClassId = typeof(CompaniesResources).Name ; allowCommentsFieldElement.ChoicesConfig.Add( new ChoiceElement(allowCommentsFieldElement.ChoicesConfig) Text = Res.Get(typeof(CompaniesResources).Name, "AllowComments") ); moreOptionsSection.Fields.Add(allowCommentsFieldElement); detailView.Sections.Add(moreOptionsSection); #endregionHi Daniel ,
Here is the default configuration that we use for news
var allowCommentsFieldElement = new ChoiceFieldElement(moreOptionsSection.Fields) FieldName = "AllowComments", ID = "allowCommentsField", Title = (displayMode == FieldDisplayMode.Read) ? "AllowComments" : string.Empty, DataFieldName = "AllowComments", DisplayMode = displayMode, RenderChoiceAs = RenderChoicesAs.SingleCheckBox, CssClass = "sfCheckBox sfFormSeparator", WrapperTag = HtmlTextWriterTag.Li, ResourceClassId = typeof(NewsResources).Name ; allowCommentsFieldElement.ChoicesConfig.Add( new ChoiceElement(allowCommentsFieldElement.ChoicesConfig) Text = Res.Get(typeof(NewsResources).Name, "AllowComments"), ); moreOptionsSection.Fields.Add(allowCommentsFieldElement);Thanks.
I noticed that I didn't have the 'FieldName' property set. I cannot test it yet, since I did not yet enabled multiple languages.
I'll let you know if the problems remains.
Regards,