Class TwBlazorInputComponentBase
- Namespace
- TwBlazor
- Assembly
- TwBlazor.dll
Base class for every input component: the label, root element, read-only, disabled and validation state they share, and their connection to the form they sit in.
public class TwBlazorInputComponentBase : TwBlazorComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent, ITwInputComponent, IAsyncDisposable
- Inheritance
-
TwBlazorInputComponentBase
- Implements
- Derived
- Inherited Members
Remarks
Inside an EditForm or a TwForm, an input whose value is bound with
@bind-Value (or its own value parameter's @bind-) reports each change to the form, so validators
such as DataAnnotationsValidator run for it, and shows the form's validation message for its field.
Constructors
TwBlazorInputComponentBase()
public TwBlazorInputComponentBase()
Properties
Disabled
Gets or sets whether the input component is disabled.
[Parameter]
public bool Disabled { get; set; }
Property Value
Remarks
When true, the component is visually dimmed and cannot be interacted with.
ErrorMessage
Gets or sets the validation error message to display and associate with the input.
[Parameter]
public string ErrorMessage { get; set; }
Property Value
Remarks
Only rendered and referenced by aria-describedby when Invalid is true.
Invalid
Gets or sets whether the input component currently fails validation.
[Parameter]
public bool Invalid { get; set; }
Property Value
Remarks
When true (and ErrorMessage is set), the control is marked aria-invalid and programmatically associated with the rendered error text via aria-describedby, so assistive tech announces the error alongside the field instead of leaving it undiscoverable.
Label
Gets or sets the text label associated with the component.
[Parameter]
public string Label { get; set; }
Property Value
LabelAttributes
Gets or sets a collection of additional attributes to apply to the label element.
[Parameter]
public Dictionary<string, object> LabelAttributes { get; set; }
Property Value
Remarks
Use this property to add arbitrary HTML attributes to the rendered label, such as custom data attributes, CSS classes, or ARIA attributes. Existing attributes with the same name may be overwritten.
LabelClass
Gets or sets the classes for the label.
[Parameter]
public string LabelClass { get; set; }
Property Value
LabelClasses
Gets the CSS classes applied to the label element.
public string LabelClasses { get; }
Property Value
Remarks
Combines the default label styling (block display, margin, font size, and weight) with any custom classes specified in LabelClass.
LabelId
Gets or sets the unique identifier for the associated label element.
[Parameter]
public string LabelId { get; set; }
Property Value
Remarks
Use this property to specify the ID of a label element that is associated with the component for accessibility purposes. Setting this value enables assistive technologies to correctly identify and describe the component.
ReadOnly
Gets or sets whether the input component is readonly.
[Parameter]
public bool ReadOnly { get; set; }
Property Value
Remarks
When true, the component cannot be edited by the user but will still display its current value.
RootAttributes
Gets or sets the additional attributed applied to the root element of the component.
[Parameter]
public Dictionary<string, object> RootAttributes { get; set; }
Property Value
RootClass
Gets or sets the CSS class name applied to the root element of the component.
[Parameter]
public string RootClass { get; set; }
Property Value
RootId
Gets or sets the unique identifier for the root element.
[Parameter]
public string RootId { get; set; }
Property Value
errorId
Gets the id of the rendered error message element when the field is invalid, or null otherwise. Leaf components use this both to render the error text (via TwInputRoot) and to reference it from the control's aria-describedby, so assistive tech announces the error alongside the field.
protected string? errorId { get; }
Property Value
fieldErrorMessage
Gets the message shown under the field: ErrorMessage while Invalid is set, otherwise the enclosing form's first validation message for the field.
protected string fieldErrorMessage { get; }
Property Value
fieldIdentifier
Gets the model property the field is bound to in the enclosing form, or null when it has no form or its value is not bound to a property.
protected FieldIdentifier? fieldIdentifier { get; }
Property Value
fieldInvalid
Gets whether the field is invalid: Invalid is set, or the enclosing form has a validation message for the field.
protected bool fieldInvalid { get; }
Property Value
ownErrorMessage
Gets the field's own error message while it is invalid for a reason the form does not know about, such as a failed validator or text that could not be read, or null. Listed in the form's error summary.
protected virtual string? ownErrorMessage { get; }
Property Value
participatesInForm
Gets whether the field connects to the enclosing form itself. A field that is part of another input, such as the text field inside a date picker, leaves that to the outer input, so the form sees each field once.
protected virtual bool participatesInForm { get; }
Property Value
Methods
Close()
Closes the component's picker dialog. Override in picker components to handle close logic.
[JSInvokable("Close")]
public virtual Task Close()
Returns
CreateFieldIdentifier()
Creates the identifier of the model property the field's value is bound to. Input components override
this to build it from their value expression (supplied by @bind-Value).
protected virtual FieldIdentifier? CreateFieldIdentifier()
Returns
- FieldIdentifier?
The field identifier, or null when the value is not bound to a property.
DisposeAsync()
Releases the field's connection to its form.
public virtual ValueTask DisposeAsync()
Returns
- ValueTask
A task that completes once the field is released.
NotifyFieldChanged()
Tells the enclosing form that the field's value changed, so its validators run for the field. Does nothing outside a form.
protected void NotifyFieldChanged()
OnParametersSet()
Invoked when the component's parameters have been set. Ensures that the component has a unique identifier by generating one if none is provided.
protected override void OnParametersSet()
Remarks
If the component's identifier is not set, a unique ID is generated based on the component's type name (with a 'Tw' prefix removed if present) and a GUID. This helps ensure that each component instance can be uniquely identified, which is useful for scenarios such as associating labels with form elements or targeting elements in client-side scripts.
ValidateAsync()
Validates the field when its TwForm is submitted or validated. Components with a validator of their own override this to run it first.
public virtual Task<bool> ValidateAsync()