예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
 public TypedForm <T> AddFormValue(FormValue formValue)
 {
     _formValues.Add(formValue);
     return(this);
 }