Skip to contents

Field

A component that provides labeling and validation for form controls.

Visible on your profile

Anatomy

Import the component and assemble its parts:

API reference

Root

Groups all parts of the field. Renders a <div> element.

disabled boolean | null false
Description

Whether the component should ignore user interaction. Takes precedence over disabled on <Field.Control>.

Type
boolean | null
Default
false
name string | null —
Name
Description

Identifies the field when a form is submitted. Takes precedence over the control's name. Inside a Form with a form source, the name resolves to that source's field, unchecked.

Type
string | null
validate FieldValidate —
Description

Custom validation. Return a message or messages when the value is invalid. An empty result is valid. Asynchronous functions do not block form submission.

Type
FieldValidate
validationMode FormValidationMode 'onSubmit'
Description

When the field validates. Takes precedence over <Form validationMode>.

Type
FormValidationMode
Default
'onSubmit'
validationDebounceTime number 0
Description

How long to wait between validate callbacks when validationMode is onChange.

Type
number
Default
0
invalid boolean —
Name
Description

Whether the field is invalid. Useful when an external library owns the state.

Type
boolean
dirty boolean —
Name
Description

Whether the value has changed from its initial value.

Type
boolean
touched boolean —
Name
Description

Whether the field has been touched.

Type
boolean
field F —
Name
Description

A field of the Form's source, such as remote.fields.email. The Field shows its issues, and Field.Control takes its encoded name and value.

Type
F
type ControlType<F> —
Name
Type
ControlType<F>
render Snippet<[props: HTMLAttributes<HTMLElement>, state: FieldRootState, children: Snippet | undefined]> —
Name
Description

Replace the default <div>. Spread props onto the host element.

Type
Snippet<[props: HTMLAttributes<HTMLElement>, state: FieldRootState, children: Snippet | undefined]>
disabled boolean
Name
disabled
Description

Whether the component should ignore user interaction.

Type
boolean
touched boolean
Name
touched
Description

Whether the field has been touched.

Type
boolean
dirty boolean
Name
dirty
Description

Whether the field value has changed from its initial value.

Type
boolean
valid boolean | null
Name
valid
Description

Whether the field is valid. null means validity is not known yet.

Type
boolean | null
filled boolean
Name
filled
Description

Whether the field has a value.

Type
boolean
focused boolean
Name
focused
Description

Whether the field is focused.

Type
boolean
data-disabled
Present when the field is disabled.
data-valid
Present when the field is valid.
data-invalid
Present when the field is invalid.
data-dirty
Present when the field's value has changed.
data-touched
Present when the field has been touched.
data-filled
Present when the field is filled.
data-focused
Present when the field control is focused.

Label

An accessible label that is automatically associated with the field control. Renders a <label> element.

nativeLabel boolean true
Description

Whether the rendered element is a native <label>. Set false when render produces a different element.

Type
boolean
Default
true
render Snippet<[props: HTMLAttributes<HTMLElement>, state: FieldLabelState, children: Snippet | undefined]> —
Name
Description

Replace the default <label>. Spread props onto the host element.

Type
Snippet<[props: HTMLAttributes<HTMLElement>, state: FieldLabelState, children: Snippet | undefined]>
disabled boolean
Name
disabled
Description

Whether the component should ignore user interaction.

Type
boolean
touched boolean
Name
touched
Description

Whether the field has been touched.

Type
boolean
dirty boolean
Name
dirty
Description

Whether the field value has changed from its initial value.

Type
boolean
valid boolean | null
Name
valid
Description

Whether the field is valid. null means validity is not known yet.

Type
boolean | null
filled boolean
Name
filled
Description

Whether the field has a value.

Type
boolean
focused boolean
Name
focused
Description

Whether the field is focused.

Type
boolean
data-disabled
Present when the field is disabled.
data-valid
Present when the field is in a valid state.
data-invalid
Present when the field is in an invalid state.
data-dirty
Present when the field's value has changed.
data-touched
Present when the field has been touched.
data-filled
Present when the field is filled.
data-focused
Present when the field control is focused.

Control

The form control to label and validate. Renders an <input> element.

value string | number | null —
Name
Description

Current value. Use bind:value to share it with the parent.

Type
string | number | null
Binding
bind:value
defaultValue string | number | null —
Description

The value an empty value starts from, as on an HTML input.

Type
string | number | null
onValueChange function —
Description

Called when the user edits the control. eventDetails.cancel() vetoes the change.

Type
(value: string, eventDetails: FieldControlChangeEventDetails) => void
render Snippet<[props: HTMLAttributes<HTMLElement>, state: FieldControlState, children: Snippet | undefined]> —
Name
Description

Replace the default <input>. Spread props onto the host element.

Type
Snippet<[props: HTMLAttributes<HTMLElement>, state: FieldControlState, children: Snippet | undefined]>
disabled boolean
Name
disabled
Description

Whether the component should ignore user interaction.

Type
boolean
touched boolean
Name
touched
Description

Whether the field has been touched.

Type
boolean
dirty boolean
Name
dirty
Description

Whether the field value has changed from its initial value.

Type
boolean
valid boolean | null
Name
valid
Description

Whether the field is valid. null means validity is not known yet.

Type
boolean | null
filled boolean
Name
filled
Description

Whether the field has a value.

Type
boolean
focused boolean
Name
focused
Description

Whether the field is focused.

Type
boolean
data-disabled
Present when the field is disabled.
data-valid
Present when the field is in a valid state.
data-invalid
Present when the field is in an invalid state.
data-dirty
Present when the field's value has changed.
data-touched
Present when the field has been touched.
data-filled
Present when the field is filled.
data-focused
Present when the field control is focused.

Description

A paragraph with additional information about the field. Renders a <p> element.

render Snippet<[props: HTMLAttributes<HTMLElement>, state: FieldDescriptionState, children: Snippet | undefined]> —
Name
Description

Replace the default <p>. Spread props onto the host element.

Type
Snippet<[props: HTMLAttributes<HTMLElement>, state: FieldDescriptionState, children: Snippet | undefined]>
disabled boolean
Name
disabled
Description

Whether the component should ignore user interaction.

Type
boolean
touched boolean
Name
touched
Description

Whether the field has been touched.

Type
boolean
dirty boolean
Name
dirty
Description

Whether the field value has changed from its initial value.

Type
boolean
valid boolean | null
Name
valid
Description

Whether the field is valid. null means validity is not known yet.

Type
boolean | null
filled boolean
Name
filled
Description

Whether the field has a value.

Type
boolean
focused boolean
Name
focused
Description

Whether the field is focused.

Type
boolean
data-disabled
Present when the field is disabled.
data-valid
Present when the field is in a valid state.
data-invalid
Present when the field is in an invalid state.
data-dirty
Present when the field's value has changed.
data-touched
Present when the field has been touched.
data-filled
Present when the field is filled.
data-focused
Present when the field control is focused.

Item

Groups an individual item with its own label and description. Renders a <div> element.

disabled boolean | null false
Description

Whether the wrapped control should ignore user interaction. <Field.Root disabled> takes precedence.

Type
boolean | null
Default
false
render Snippet<[props: HTMLAttributes<HTMLElement>, state: FieldItemState, children: Snippet | undefined]> —
Name
Description

Replace the default <div>. Spread props onto the host element.

Type
Snippet<[props: HTMLAttributes<HTMLElement>, state: FieldItemState, children: Snippet | undefined]>
disabled boolean
Name
disabled
Description

Whether the component should ignore user interaction.

Type
boolean
touched boolean
Name
touched
Description

Whether the field has been touched.

Type
boolean
dirty boolean
Name
dirty
Description

Whether the field value has changed from its initial value.

Type
boolean
valid boolean | null
Name
valid
Description

Whether the field is valid. null means validity is not known yet.

Type
boolean | null
filled boolean
Name
filled
Description

Whether the field has a value.

Type
boolean
focused boolean
Name
focused
Description

Whether the field is focused.

Type
boolean
data-disabled
Present when the field is disabled.
data-valid
Present when the field is in a valid state.
data-invalid
Present when the field is in an invalid state.
data-dirty
Present when the field's value has changed.
data-touched
Present when the field has been touched.
data-filled
Present when the field is filled.
data-focused
Present when the field control is focused.

Error

An error message displayed if the field control fails validation. Renders a <div> element.

match boolean | keyof ValidityState —
Name
Description

Which validity flag shows this message. true always shows it. A string matches that ValidityState flag. Omit it, or pass false, to show form and client errors.

Type
boolean | keyof ValidityState
render Snippet<[props: HTMLAttributes<HTMLElement>, state: FieldErrorState, children: Snippet | undefined]> —
Name
Description

Replace the default <div>. Spread props onto the host element.

Type
Snippet<[props: HTMLAttributes<HTMLElement>, state: FieldErrorState, children: Snippet | undefined]>
transitionStatus FieldTransitionStatus
Name
transitionStatus
Description

The transition status of the error message.

Type
FieldTransitionStatus
disabled boolean
Name
disabled
Description

Whether the component should ignore user interaction.

Type
boolean
touched boolean
Name
touched
Description

Whether the field has been touched.

Type
boolean
dirty boolean
Name
dirty
Description

Whether the field value has changed from its initial value.

Type
boolean
valid boolean | null
Name
valid
Description

Whether the field is valid. null means validity is not known yet.

Type
boolean | null
filled boolean
Name
filled
Description

Whether the field has a value.

Type
boolean
focused boolean
Name
focused
Description

Whether the field is focused.

Type
boolean
data-disabled
Present when the field is disabled.
data-valid
Present when the field is in a valid state.
data-invalid
Present when the field is in an invalid state.
data-dirty
Present when the field's value has changed.
data-touched
Present when the field has been touched.
data-filled
Present when the field is filled.
data-focused
Present when the field control is focused.
data-starting-style
Present when the error message begins animating in.
data-ending-style
Present when the error message is animating out.

Validity

Renders a custom message from the field's validity.

children Snippet<[state: FieldValidityState]> —
Description

Receives the field validity state.

Type
Snippet<[state: FieldValidityState]>
validity { badInput: boolean; customError: boolean; patternMismatch: boolean; rangeOverflow: boolean; rangeUnderflow: boolean; stepMismatch: boolean; tooLong: boolean; tooShort: boolean; typeMismatch: boolean; valueMissing: boolean; valid: boolean | null; }
Name
validity
Description

The validity state.

Type
{ badInput: boolean; customError: boolean; patternMismatch: boolean; rangeOverflow: boolean; rangeUnderflow: boolean; stepMismatch: boolean; tooLong: boolean; tooShort: boolean; typeMismatch: boolean; valueMissing: boolean; valid: boolean | null; }
transitionStatus FieldTransitionStatus
Name
transitionStatus
Description

The transition status of the invalid state.

Type
FieldTransitionStatus
value unknown
Name
value
Type
unknown
error string
Name
error
Type
string
errors string[]
Name
errors
Type
string[]
initialValue unknown
Name
initialValue
Type
unknown