HTMLFormElement
Represents the form element.
using AngleSharp.DOM.Collections;
namespace AngleSharp.DOM.Html
{
[DOM("HTMLFormElement")]
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];
}
}
[DOM("isValid")]
public bool IsValid {
get {
return true;
}
}
[DOM("name")]
public string Name {
get {
return GetAttribute("name");
}
set {
SetAttribute("name", value);
}
}
[DOM("length")]
public int Length {
get {
return _elements.Length;
}
}
[DOM("elements")]
public HTMLFormControlsCollection Elements {
get {
return _elements;
}
}
[DOM("acceptCharset")]
public string AcceptCharset {
get {
return GetAttribute("acceptCharset");
}
set {
SetAttribute("acceptCharset", value);
}
}
[DOM("action")]
public string Action {
get {
return GetAttribute("action");
}
set {
SetAttribute("action", value);
}
}
[DOM("autocomplete")]
public PowerState Autocomplete {
get {
return Element.ToEnum(GetAttribute("autocomplete"), PowerState.On);
}
set {
SetAttribute("autocomplete", value.ToString());
}
}
[DOM("enctype")]
public string Enctype {
get {
return CheckEncType(GetAttribute("enctype"));
}
set {
SetAttribute("enctype", CheckEncType(value));
}
}
[DOM("encoding")]
public string Encoding {
get {
return Enctype;
}
set {
Enctype = value;
}
}
[DOM("method")]
public HttpMethod Method {
get {
return Element.ToEnum(GetAttribute("method"), HttpMethod.GET);
}
set {
SetAttribute("method", value.ToString());
}
}
[DOM("noValidate")]
public bool NoValidate {
get {
return GetAttribute("novalidate") != null;
}
set {
SetAttribute("novalidate", value ? string.Empty : null);
}
}
[DOM("target")]
public string Target {
get {
return GetAttribute("target");
}
set {
SetAttribute("target", value);
}
}
protected internal override bool IsSpecial => true;
internal HTMLFormElement()
{
_name = "form";
_elements = new HTMLFormControlsCollection();
}
[DOM("submit")]
public HTMLFormElement Submit()
{
return this;
}
[DOM("reset")]
public HTMLFormElement Reset()
{
return this;
}
[DOM("checkValidity")]
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";
}
}
protected override void Register(Document document)
{
if (document is HTMLDocument)
((HTMLDocument)document).Forms.Add(this);
}
protected override void Unregister(Document document)
{
if (document is HTMLDocument)
((HTMLDocument)document).Forms.Remove(this);
}
}
}