Ejemplo n.º 1
0
        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));
        }
        protected IHtmlString RenderFormField(WizardStep step)
        {
            var form     = step.Form;
            var html     = FormsPage.RenderModelFields(form, RequestContext).ToString();
            var xelement = XElement.Parse(html);

            foreach (var element in xelement.Descendants())
            {
                var nameAttr = element.Attribute("name");
                if (nameAttr != null)
                {
                    var stepIndex = Wizard.Steps.IndexOf(step) + 1;

                    nameAttr.Value = String.Format("step-{0}-{1}", stepIndex, nameAttr.Value);
                }

                var depAttr = element.Attribute("data-dependency");
                if (depAttr != null)
                {
                    var stepIndex = Wizard.Steps.IndexOf(step) + 1;

                    var dependencies = JsonConvert.DeserializeObject <DependencyModel[]>(depAttr.Value);
                    foreach (var dep in dependencies)
                    {
                        dep.Field = String.Format("step-{0}-{1}", stepIndex, dep.Field);
                    }

                    var json = JsonConvert.SerializeObject(dependencies, new JsonSerializerSettings {
                        ContractResolver = new CamelCasePropertyNamesContractResolver()
                    });

                    depAttr.Value = json;
                }
            }

            return(new HtmlString(xelement.ToString()));
        }
 public ControlsGroup(FormsPage page) : this(page.Output, page.FormRenderer)
 {
 }
Ejemplo n.º 4
0
 public FieldsRow(FormsPage page, FormRenderer renderer) : this(page.Output, renderer)
 {
 }
Ejemplo n.º 5
0
        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());
            }
        }