AngleSharp by Florian Rappl

<PackageReference Include="AngleSharp" Version="0.8.5" />

.NET API 1,113,600 bytes

 HtmlFormControlElement

Represents the base class for all HTML form control elements.
using AngleSharp.Dom.Collections; using AngleSharp.Extensions; using AngleSharp.Html; using System.Collections.Generic; using System.Linq; namespace AngleSharp.Dom.Html { internal abstract class HtmlFormControlElement : HtmlElement, ILabelabelElement, IValidation { private readonly NodeList _labels; private readonly ValidityState _vstate; private string _error; public string Name { get { return GetOwnAttribute(AttributeNames.Name); } set { SetOwnAttribute(AttributeNames.Name, value); } } public IHtmlFormElement Form => GetAssignedForm(); public bool IsDisabled { get { if (GetOwnAttribute(AttributeNames.Disabled) == null) return IsFieldsetDisabled(); return true; } set { SetOwnAttribute(AttributeNames.Disabled, value ? string.Empty : null); } } public bool Autofocus { get { return GetOwnAttribute(AttributeNames.AutoFocus) != null; } set { SetOwnAttribute(AttributeNames.AutoFocus, value ? string.Empty : null); } } public bool SupportsLabels => true; public INodeList Labels => _labels; public string ValidationMessage { get { if (!_vstate.IsCustomError) return string.Empty; return _error; } } public bool WillValidate { get { if (!IsDisabled) return CanBeValidated(); return false; } } public IValidityState Validity { get { Check(_vstate); return _vstate; } } public HtmlFormControlElement(Document owner, string name, string prefix, NodeFlags flags = NodeFlags.None) : base(owner, name, prefix, flags | NodeFlags.Special) { _vstate = new ValidityState(); _labels = new NodeList(); } public override INode Clone(bool deep = true) { HtmlFormControlElement htmlFormControlElement = (HtmlFormControlElement)base.Clone(deep); htmlFormControlElement.SetCustomValidity(_error); return htmlFormControlElement; } public bool CheckValidity() { if (WillValidate) return Validity.IsValid; return false; } public void SetCustomValidity(string error) { _vstate.IsCustomError = !string.IsNullOrEmpty(error); _error = error; } protected virtual bool IsFieldsetDisabled() { IEnumerable<IHtmlFieldSetElement> enumerable = this.GetAncestors().OfType<IHtmlFieldSetElement>(); foreach (IHtmlFieldSetElement item in enumerable) { if (item.IsDisabled) { INode parent = item.ChildNodes.FirstOrDefault((INode m) => m is IHtmlLegendElement); return !this.IsDescendantOf(parent); } } return false; } internal virtual void ConstructDataSet(FormDataSet dataSet, HtmlElement submitter) { } internal virtual void Reset() { } protected virtual void Check(ValidityState state) { } protected abstract bool CanBeValidated(); } }