London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
AI OnAI Off
London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
Have you tried like
chkbox.Validators = typeof(EPiServer.Forms.Implementation.Validation.RequiredValidator).FullName;
The following article is very useful in creating a form using API
http://www.aperturelabs.biz/blog/creating-episerver-forms-via-the-api/
Hello,
I have a page type which automatically creates an Episerver form including multiple form elements and includes it in a ContentArea. Smooth sailing so far. But when I try to make one of these generated fields required by default nothing quite seems to work.
I have tried variations of the following...
private void AddCheckBox(string label, FormContainerBlock container, IContentRepository repo) { var checkBox = repo.GetDefault<ChoiceElementBlock>(ContentReference.GlobalBlockFolder); var option = new OptionItem() { Caption = label }; checkBox.Items = new List<OptionItem>() { option }; checkBox.AllowMultiSelect = true; checkBox.Validators = "EPiServer.Forms.Implementation.Validation.RequiredValidator"; var reference = repo.Save((IContent)checkBox, SaveAction.Publish); container.ElementsArea.Items.Add(new ContentAreaItem() { ContentLink = reference }); }
This does make the field required in the CMS view. But on the rendered view, even if the user has checked the checkbox it still spits out the "This field is required" message.
I can find little documentation on the subject and it'd be great to hear if someone has had similiar problems and any potential steps taken to solve it?
-------
This is how the EPiServer.Forms.Implementation.Elements.BaseClass.ValidateableElementBlockBase.Validators property is documented. Presumably this string can be set manually when generating the form, but the format in which it should be structured is completely foreign to me.
Documentation