AngleSharp by AngleSharp

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

.NET API 1,214,976 bytes

 HtmlInputElement

Represents an HTML input element.
using AngleSharp.Dom.Css; using AngleSharp.Dom.Events; using AngleSharp.Dom.Io; using AngleSharp.Extensions; using AngleSharp.Html; using AngleSharp.Html.InputTypes; using AngleSharp.Services; using System; namespace AngleSharp.Dom.Html { internal sealed class HtmlInputElement : HtmlTextFormControlElement, IHtmlInputElement, IHtmlElement, IElement, INode, IEventTarget, IMarkupFormattable, IParentNode, IChildNode, INonDocumentTypeChildNode, IElementCssInlineStyle, IGlobalEventHandlers, IValidation { private BaseInputType _type; private bool? _checked; public override string DefaultValue { get { return this.GetOwnAttribute(AttributeNames.Value) ?? string.Empty; } set { this.SetOwnAttribute(AttributeNames.Value, value, false); } } public bool IsDefaultChecked { get { return this.HasOwnAttribute(AttributeNames.Checked); } set { this.SetOwnAttribute(AttributeNames.Checked, value ? string.Empty : null, false); } } public bool IsChecked { get { if (!_checked.HasValue) return IsDefaultChecked; return _checked.Value; } set { _checked = value; } } public string Type { get { return _type.Name; } set { this.SetOwnAttribute(AttributeNames.Type, value, false); } } public bool IsIndeterminate { get; set; } public bool IsMultiple { get { return this.HasOwnAttribute(AttributeNames.Multiple); } set { this.SetOwnAttribute(AttributeNames.Multiple, value ? string.Empty : null, false); } } public DateTime? ValueAsDate { get { return _type.ConvertToDate(base.Value); } set { if (!value.HasValue) base.Value = string.Empty; else base.Value = _type.ConvertFromDate(value.Value); } } public double ValueAsNumber { get { return _type.ConvertToNumber(base.Value) ?? NaN; } set { if (double.IsInfinity(value)) throw new DomException(DomError.TypeMismatch); if (double.IsNaN(value)) base.Value = string.Empty; else base.Value = _type.ConvertFromNumber(value); } } public string FormAction { get { IHtmlFormElement form = base.Form; if (form == null) return string.Empty; return form.Action; } set { IHtmlFormElement form = base.Form; if (form != null) form.Action = value; } } public string FormEncType { get { IHtmlFormElement form = base.Form; if (form == null) return string.Empty; return form.Enctype; } set { IHtmlFormElement form = base.Form; if (form != null) form.Enctype = value; } } public string FormMethod { get { IHtmlFormElement form = base.Form; if (form == null) return string.Empty; return form.Method; } set { IHtmlFormElement form = base.Form; if (form != null) form.Method = value; } } public bool FormNoValidate { get { return base.Form?.NoValidate ?? false; } set { IHtmlFormElement form = base.Form; if (form != null) form.NoValidate = value; } } public string FormTarget { get { IHtmlFormElement form = base.Form; if (form == null) return string.Empty; return form.Target; } set { IHtmlFormElement form = base.Form; if (form != null) form.Target = value; } } public string Accept { get { return this.GetOwnAttribute(AttributeNames.Accept); } set { this.SetOwnAttribute(AttributeNames.Accept, value, false); } } public Alignment Align { get { return this.GetOwnAttribute(AttributeNames.Align).ToEnum(Alignment.Left); } set { this.SetOwnAttribute(AttributeNames.Align, value.ToString(), false); } } public string AlternativeText { get { return this.GetOwnAttribute(AttributeNames.Alt); } set { this.SetOwnAttribute(AttributeNames.Alt, value, false); } } public string Autocomplete { get { return this.GetOwnAttribute(AttributeNames.AutoComplete); } set { this.SetOwnAttribute(AttributeNames.AutoComplete, value, false); } } public IFileList Files => (_type as FileInputType)?.Files; public IHtmlDataListElement List { get { string ownAttribute = this.GetOwnAttribute(AttributeNames.List); return base.Owner?.GetElementById(ownAttribute) as IHtmlDataListElement; } } public string Maximum { get { return this.GetOwnAttribute(AttributeNames.Max); } set { this.SetOwnAttribute(AttributeNames.Max, value, false); } } public string Minimum { get { return this.GetOwnAttribute(AttributeNames.Min); } set { this.SetOwnAttribute(AttributeNames.Min, value, false); } } public string Pattern { get { return this.GetOwnAttribute(AttributeNames.Pattern); } set { this.SetOwnAttribute(AttributeNames.Pattern, value, false); } } public int Size { get { return this.GetOwnAttribute(AttributeNames.Size).ToInteger(20); } set { this.SetOwnAttribute(AttributeNames.Size, value.ToString(), false); } } public string Source { get { return this.GetOwnAttribute(AttributeNames.Src); } set { this.SetOwnAttribute(AttributeNames.Src, value, false); } } public string Step { get { return this.GetOwnAttribute(AttributeNames.Step); } set { this.SetOwnAttribute(AttributeNames.Step, value, false); } } public string UseMap { get { return this.GetOwnAttribute(AttributeNames.UseMap); } set { this.SetOwnAttribute(AttributeNames.UseMap, value, false); } } public int DisplayWidth { get { return this.GetOwnAttribute(AttributeNames.Width).ToInteger(OriginalWidth); } set { this.SetOwnAttribute(AttributeNames.Width, value.ToString(), false); } } public int DisplayHeight { get { return this.GetOwnAttribute(AttributeNames.Height).ToInteger(OriginalHeight); } set { this.SetOwnAttribute(AttributeNames.Height, value.ToString(), false); } } public int OriginalWidth => (_type as ImageInputType)?.Width ?? 0; public int OriginalHeight => (_type as ImageInputType)?.Height ?? 0; internal bool IsVisited { get; set; } internal bool IsActive { get; set; } internal bool IsMutable { get { if (!base.IsDisabled) return !base.IsReadOnly; return false; } } static HtmlInputElement() { Element.RegisterCallback(AttributeNames.Type, delegate(HtmlInputElement element, string value) { element.UpdateType(value); }); } public HtmlInputElement(Document owner, string prefix = null) : base(owner, TagNames.Input, prefix, NodeFlags.SelfClosing) { } public override void DoClick() { if (!IsClickedCancelled()) { string type = Type; if (type.Is(InputTypeNames.Submit)) base.Form?.SubmitAsync(); else if (type.Is(InputTypeNames.Reset)) { base.Form?.Reset(); } } } public sealed override INode Clone(bool deep = true) { HtmlInputElement obj = (HtmlInputElement)base.Clone(deep); obj._checked = _checked; obj.UpdateType(_type.Name); return obj; } internal override FormControlState SaveControlState() { return new FormControlState(base.Name, Type, base.Value); } internal override void RestoreFormControlState(FormControlState state) { if (state.Type.Is(Type) && state.Name.Is(base.Name)) base.Value = state.Value; } public void StepUp(int n = 1) { _type.DoStep(n); } public void StepDown(int n = 1) { _type.DoStep(-n); } internal override void SetupElement() { base.SetupElement(); string ownAttribute = this.GetOwnAttribute(AttributeNames.Type); UpdateType(ownAttribute); } private void UpdateType(string type) { IInputTypeFactory factory = base.Owner.Options.GetFactory<IInputTypeFactory>(); _type = factory.Create(this, type); } internal override void ConstructDataSet(FormDataSet dataSet, IHtmlElement submitter) { if (_type.IsAppendingData(submitter)) _type.ConstructDataSet(dataSet); } internal override void Reset() { base.Reset(); _checked = null; UpdateType(Type); } protected override void Check(ValidityState state) { base.Check(state); _type.Check(state); } protected override bool CanBeValidated() { if (_type.CanBeValidated) return base.CanBeValidated(); return false; } } }