Skip to content

InputBinding

Defined in: InputBinding.ts:5, InputBinding.ts:128

Binding for text input elements

Key features:

  • Supports text, number, and date inputs
  • Handles intermediate values during typing
  • Auto-finalizes values on blur
  • Manages error states and ARIA attributes
  • FormBinding

Config = object & ({ getter: () => string | null; setter: (value: string) => void; type?: StringType; valueAs?: "string"; } | { getter: () => number | null; setter: (value: number | null) => void; type?: NumericValueType; valueAs: "number"; } | { getter: () => string | null; setter: (value: Date | null) => void; type?: DateValueType; valueAs: "date"; })

Defined in: InputBinding.ts:24

optional aria-describedby?: Attrs["aria-describedby"]

[Extend] IDs of the elements describing the input; the ID of the error text is added while errors are reported

optional id?: Attrs["id"]

[Override] ID of the input element

optional onBlur?: Attrs["onBlur"]

[Extend] Blur handler

optional onChange?: Attrs["onChange"]

[Extend] Change handler

optional onFocus?: Attrs["onFocus"]

[Extend] Focus handler

{ getter: () => string | null; setter: (value: string) => void; type?: StringType; valueAs?: "string"; }

getter: () => string | null

Get the value from the model

string | null

setter: (value: string) => void

@action

Set the value to the model

string

void

optional type?: StringType

Type of form control.

When unspecified, it is deduced from the valueAs.

"text" - when valueAs is undefined or "string"

optional valueAs?: "string"

Value type of the input element. It determines how getter/setter should handle the value.


{ getter: () => number | null; setter: (value: number | null) => void; type?: NumericValueType; valueAs: "number"; }

getter: () => number | null

Get the value from the model

number | null

setter: (value: number | null) => void

@action

Set the value to the model

number | null

void

optional type?: NumericValueType

Type of form control.

When unspecified, it is deduced from the valueAs.

"number" - when valueAs is "number"

valueAs: "number"

Value type of the input element. It determines how getter/setter should handle the value.


{ getter: () => string | null; setter: (value: Date | null) => void; type?: DateValueType; valueAs: "date"; }

getter: () => string | null

Get the value from the model

String representation of the date. As Date instance has no distinction between date and datetime, it's developers' responsibility to format the date correctly.

type attr Expected format Example
date YYYY-MM-DD 2024-12-31
datetime-local YYYY-MM-DDTHH:mm 2024-12-31T23:59
time HH:mm or HH:mm:ss 23:59 or 23:59:59
week YYYY-Www 2024-W52
month YYYY-MM 2024-12

The Date given to the setter is the element's wall clock read as UTC, not the instant in the browser's timezone: date is midnight UTC, time is on 1970-01-01 UTC, and datetime-local is the entered date-time as UTC. toISOString() thus formats it back to the same wall clock, which the getter slices down to the format of the type.

string | null

date.toISOString().split("T")[0]

setter: (value: Date | null) => void

@action

Set the value to the model

Date | null

void

optional type?: DateValueType

Type of form control.

When unspecified, it is deduced from the valueAs.

"date" - when valueAs is "date"

valueAs: "date"

Value type of the input element. It determines how getter/setter should handle the value.

new InputBinding(field, config): InputBinding

Defined in: InputBinding.ts:129

FormField

InputBinding.Config

InputBinding

config: InputBinding.Config

Defined in: InputBinding.ts:131

FormBinding.config


onBlur: FocusEventHandler<HTMLInputElement>

Defined in: InputBinding.ts:180


onChange: ChangeEventHandler<HTMLInputElement, HTMLInputElement>

Defined in: InputBinding.ts:154

@action


onFocus: FocusEventHandler<HTMLInputElement>

Defined in: InputBinding.ts:185


get errorMessages(): string | null

Defined in: InputBinding.ts:191

string | null

@computed


get props(): object

Defined in: InputBinding.ts:196

Binding properties which passed to the view component

object

aria-describedby: string | undefined

aria-errormessage: string | undefined

aria-invalid: boolean | undefined

id: string

onBlur: FocusEventHandler<HTMLInputElement>

onChange: ChangeEventHandler<HTMLInputElement, HTMLInputElement>

onFocus: FocusEventHandler<HTMLInputElement>

type: HTMLInputTypeAttribute

value: string | number | readonly string[]

FormBinding.props


get type(): HTMLInputTypeAttribute

Defined in: InputBinding.ts:140

HTMLInputTypeAttribute


get value(): string | number | readonly string[]

Defined in: InputBinding.ts:136

string | number | readonly string[]