HTMLFormElement
Represents the form element.
using AngleSharp.DOM.Collections;
namespace AngleSharp.DOM.Html
{
public sealed class HTMLFormElement : HTMLElement
{
internal const string Tag = "form";
private HTMLFormControlsCollection _elements;
public Element this[int index] {
get {
return _elements[index];
}
}
public object this[string name] {
get {
return _elements[name];
}
}
public bool IsValid => true;
public string Name {
get {
return GetAttribute("name");
}
set {
SetAttribute("name", value);
}
}
public int Length => _elements.Length;
public HTMLFormControlsCollection Elements => _elements;
public string AcceptCharset {
get {
return GetAttribute("acceptCharset");
}
set {
SetAttribute("acceptCharset", value);
}
}
public string Action {
get {
return GetAttribute("action");
}
set {
SetAttribute("action", value);
}
}
public PowerState Autocomplete {
get {
return Element.ToEnum(GetAttribute("autocomplete"), PowerState.On);
}
set {
SetAttribute("autocomplete", value.ToString());
}
}
public string Enctype {
get {
return CheckEncType(GetAttribute("enctype"));
}
set {
SetAttribute("enctype", CheckEncType(value));
}
}
public string Encoding {
get {
return Enctype;
}
set {
Enctype = value;
}
}
public HttpMethod Method {
get {
return Element.ToEnum(GetAttribute("method"), HttpMethod.GET);
}
set {
SetAttribute("method", value.ToString());
}
}
public bool NoValidate {
get {
return GetAttribute("novalidate") != null;
}
set {
SetAttribute("novalidate", value ? string.Empty : null);
}
}
public string Target {
get {
return GetAttribute("target");
}
set {
SetAttribute("target", value);
}
}
protected internal override bool IsSpecial => true;
internal HTMLFormElement()
{
_name = "form";
_elements = new HTMLFormControlsCollection();
}
public HTMLFormElement Submit()
{
return this;
}
public HTMLFormElement Reset()
{
return this;
}
public bool CheckValidity()
{
return true;
}
private string CheckEncType(string encType)
{
switch (encType) {
case "application/x-www-form-urlencoded":
case "multipart/form-data":
case "text/plain":
return encType;
default:
return "application/x-www-form-urlencoded";
}
}
}
}