public static FormValue FromElement(ElementWrapper element) { var formValue = new FormValue(element.AttributeOrEmpty("name")); formValue.SetDisabled(element.HasAttribute("disabled")); switch (element.TagName.ToLower()) { case "input": return(FromInput(element, formValue)); case "textarea": return(FromTextArea(element, formValue)); case "select": return(FromSelect(element, formValue)); default: throw new Exception("Unhandled tag: " + element.TagName); } }
public static FormValue FromInput(ElementWrapper input, FormValue formValue) { var type = input.HasAttribute("type") ? input.Attribute("type").ToLower() : "text"; formValue .SetValue(input.HasAttribute("value") ? input.Attribute("value") : null) .SetReadonly(input.HasAttribute("readonly")); if (type == "checkbox" || type == "radio") { if (string.IsNullOrEmpty(formValue.Value)) { formValue.SetValue("on"); } if (!input.HasAttribute("checked")) { formValue.SetSend(false); } } return(formValue); }
public TypedForm <T> AddFormValue(FormValue formValue) { _formValues.Add(formValue); return(this); }