Skip to content

FormField

Defined in: field.ts:16, field.ts:263

Form field that tracks input state and validation errors

Key features:

  • Tracks touch state
  • Handles intermediate (partial) input states
  • Manages error reporting
  • Supports auto-finalization of intermediate values

ChangeType = "final" | "intermediate"

Defined in: field.ts:277

The type of change that has occurred in the field.

  • "final" - The input is complete and no further update is necessary to make it valid.
  • "intermediate" - The input is incomplete and does not yet conform to the expected format.

Name<T> = FormField.NameStrict<T> | FormField.NameAugmented<T>

Defined in: field.ts:269

Field name


NameAugmented<T> = `${FormField.NameStrict<T>}:${string}`

Defined in: field.ts:267

Augmented field name with an arbitrary suffix


NameStrict<T> = keyof T & string

Defined in: field.ts:265

Strict field name

readonly fieldName: string

Defined in: field.ts:26


readonly id: string

Defined in: field.ts:25

Identity of the field instance

Unique per instance and fixed for its lifetime, but not reproducible: a server render and the client render that hydrates it produce different values. For an id that reaches the DOM, use stableId instead.


readonly validator: Validator<any>

Defined in: field.ts:27


get errors(): ReadonlySet<string>

Defined in: field.ts:126

Error messages for the field

Regardless of isErrorReported, this value is always up-to-date.

ReadonlySet<string>

@computed


get hasErrors(): boolean

Defined in: field.ts:136

Whether the field has errors

Regardless of isErrorReported, this value is always up-to-date.

boolean

@computed


get isChanged(): boolean

Defined in: field.ts:96

Whether the field value is changed

boolean


get isErrorReported(): boolean | undefined

Defined in: field.ts:115

Whether the error states has been reported.

Check this value to determine if errors should be displayed to the user.

  • Error reporting is delayed until validation is complete.
  • It can be used directly with the aria-invalid attribute.

boolean | undefined

  • undefined - Validity is undetermined (not yet reported)
  • false - Field is valid
  • true - Field is invalid

@computed


get isIntermediate(): boolean

Defined in: field.ts:89

Whether the field value is intermediate (partial input)

- Typing "user@" in an email field
- Typing a partial date "2024-"

Intermediate values are automatically finalized after a delay

boolean


get isTouched(): boolean

Defined in: field.ts:75

Whether the field is touched.

A field becomes touched when the user interacts with it.

boolean


get stableId(): string

Defined in: field.ts:64

Id for associating a label with the field's form control

  • Once the form's Form.stableId is assigned an id of its own, that id and fieldName, joined by :
  • Until then, the field's own id: unique on the page, but different between a server render and the client render that hydrates it
  • Use this, not id, for anything that reaches the DOM

Form.stableId

string


finalizeChangeIfNeeded(): void

Defined in: field.ts:207

@action

Finalize the intermediate change if needed (usually triggered by onBlur)

void


markAsChanged(type?): void

Defined in: field.ts:179

@action

Mark the field as changed

It's usually triggered by onChange.

FormField.ChangeType = "final"

Default to "final"

void

  • "final" immediately reports errors
  • "intermediate" schedules auto-finalization after delay

markAsTouched(): void

Defined in: field.ts:163

@action

Mark the field as touched

It's usually triggered by onFocus.

void


reportError(): void

Defined in: field.ts:201

@action

Report the errors of the field.

It will wait until the validation is up-to-date before reporting the errors.

void


reset(): void

Defined in: field.ts:150

@action

Reset the field state

void

  • Clears touched state
  • Clears change state
  • Clears error reporting
  • Cancels any pending auto-finalization