private void AddRendererSettings() { var json = JsonConvert.SerializeObject(new { Type = _page.FormRenderer.GetType().AssemblyQualifiedName, Settings = _page.FormRenderer }); _page.WriteLiteral(" data-renderer=\"" + HttpUtility.HtmlAttributeEncode(json) + "\""); }
protected virtual void Dispose(bool disposing) { if (!_disposed) { _page.WriteLiteral("</div>"); _disposed = true; } }
public FieldsGroup(FormsPage page, string extraClass) { _page = page; var cssClass = page.FormRenderer.ParentGroupClass + "-group"; if (!String.IsNullOrEmpty(extraClass)) { cssClass += " " + extraClass; } page.WriteLiteral(String.Format("<div class=\"{0}\">", cssClass)); }
public HtmlForm(FormsPage page, object htmlAttributes) { _page = page; var htmlAttributesDictionary = new Dictionary <string, IList <string> > { { "class", new List <string> { "form", "formbuilder-" + page.Form.Name.ToLowerInvariant() } } }; if (page.FormRenderer.Horizontal) { htmlAttributesDictionary["class"].Add("form-horizontal"); } var htmlElementAttributes = page.Form.Attributes.OfType <HtmlTagAttribute>(); var action = (string)null; foreach (var attr in htmlElementAttributes) { if (attr.Attribute == "method") { continue; } if (attr.Attribute == "action") { action = attr.Value; continue; } IList <string> list; if (!htmlAttributesDictionary.TryGetValue(attr.Attribute, out list)) { htmlAttributesDictionary.Add(attr.Attribute, new List <string>()); } htmlAttributesDictionary[attr.Attribute].Add(attr.Value); } var dictionary = Functions.ObjectToDictionary(htmlAttributes); if (dictionary != null) { if (dictionary.ContainsKey("class")) { htmlAttributesDictionary["class"].Add((string)dictionary["class"]); } if (dictionary.ContainsKey("action")) { action = (string)dictionary["action"]; } } page.WriteLiteral("<form method=\"post\""); if (!String.IsNullOrEmpty(action)) { page.WriteLiteral(String.Format(" action=\"{0}\"", action)); } foreach (var kvp in htmlAttributesDictionary) { page.WriteLiteral(" " + kvp.Key + "=\""); foreach (var itm in kvp.Value) { page.WriteLiteral(itm + " "); } page.WriteLiteral("\""); } if (page.Form.HasFileUpload) { page.WriteLiteral(" enctype=\"multipart/form-data\""); } AddRendererSettings(); page.WriteLiteral(" data-culture=\"" + CultureInfo.CurrentCulture.Name + "\""); page.WriteLiteral(">"); page.WriteLiteral("<input type=\"hidden\" name=\"__type\" value=\"" + HttpUtility.HtmlAttributeEncode(page.Form.Name) + "\" />"); foreach (var field in page.Form.Fields.Where(f => f.IsHiddenField)) { AddHiddenField(field.Name, field.Id, field.Value == null ? String.Empty : field.GetValueAsString()); } if (!page.Form.DisableAntiForgery) { page.WriteLiteral(AntiForgery.GetHtml()); } }