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
- Name
- Description
Whether the component should ignore user interaction. Takes precedence over
disabledon<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 aformsource, the name resolves to that source's field, unchecked.- Type
string | null
validate FieldValidate —
- Name
- 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'
- Name
- Description
When the field validates. Takes precedence over
<Form validationMode>.- Type
FormValidationMode- Default
'onSubmit'
validationDebounceTime number 0
- Description
How long to wait between
validatecallbacks whenvalidationModeisonChange.- 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>. Spreadpropsonto 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.
nullmeans 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
data-valid
data-invalid
data-dirty
data-touched
data-filled
data-focused
Label
An accessible label that is automatically associated with the field control. Renders a <label> element.
nativeLabel boolean true
- Name
- Description
Whether the rendered element is a native
<label>. Setfalsewhenrenderproduces a different element.- Type
boolean- Default
true
render Snippet<[props: HTMLAttributes<HTMLElement>, state: FieldLabelState, children: Snippet | undefined]> —
- Name
- Description
Replace the default
<label>. Spreadpropsonto 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.
nullmeans 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
data-valid
data-invalid
data-dirty
data-touched
data-filled
data-focused
Control
The form control to label and validate. Renders an <input> element.
value string | number | null —
- Name
- Description
Current value. Use
bind:valueto share it with the parent.- Type
string | number | null- Binding
bind:value
defaultValue string | number | null —
- Name
- Description
The value an empty
valuestarts from, as on an HTML input.- Type
string | number | null
onValueChange function —
- Name
- 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>. Spreadpropsonto 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.
nullmeans 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
data-valid
data-invalid
data-dirty
data-touched
data-filled
data-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>. Spreadpropsonto 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.
nullmeans 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
data-valid
data-invalid
data-dirty
data-touched
data-filled
data-focused
Item
Groups an individual item with its own label and description. Renders a <div> element.
disabled boolean | null false
- Name
- 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>. Spreadpropsonto 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.
nullmeans 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
data-valid
data-invalid
data-dirty
data-touched
data-filled
data-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.
truealways shows it. A string matches thatValidityStateflag. Omit it, or passfalse, 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>. Spreadpropsonto 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.
nullmeans 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
data-valid
data-invalid
data-dirty
data-touched
data-filled
data-focused
data-starting-style
data-ending-style
Validity
Renders a custom message from the field's validity.
children Snippet<[state: FieldValidityState]> —
- Name
- 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