Class: FieldApi<TParentData, TName, TFieldValidator, TFormValidator, TData>#
A class representing the API for managing a form field.
Normally, you will not need to create a new FieldApi instance directly.
Instead, you will use a framework hook/function like useField or createField
to create a new instance for you that uses your framework's reactivity model.
However, if you need to create a new instance manually, you can do so by calling
the new FieldApi constructor.
Type Parameters#
• TParentData
• TName extends DeepKeys<TParentData>
• TFieldValidator extends Validator<DeepValue<TParentData, TName>, unknown> | undefined = undefined
• TFormValidator extends Validator<TParentData, unknown> | undefined = undefined
• TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>
Constructors#
new FieldApi()#
new FieldApi<TParentData, TName, TFieldValidator, TFormValidator, TData>(opts): FieldApi<TParentData, TName, TFieldValidator, TFormValidator, TData>
Initializes a new FieldApi instance.
Parameters#
opts#
FieldApiOptions<TParentData, TName, TFieldValidator, TFormValidator, TData>
Returns#
FieldApi<TParentData, TName, TFieldValidator, TFormValidator, TData>
Defined in#
packages/form-core/src/FieldApi.ts:477
Properties#
form#
form: FormApi<TParentData, TFormValidator>;
A reference to the form API instance.
Defined in#
packages/form-core/src/FieldApi.ts:441
name#
name: unknown extends TParentData ? string : TParentData extends readonly any[] & IsTuple<TParentData> ? PrefixTupleAccessor<TParentData<TParentData>, AllowedIndexes<TParentData<TParentData>, never>, []> : TParentData extends any[] ? PrefixArrayAccessor<TParentData<TParentData>, [any]> : TParentData extends Date ? never : TParentData extends object ? PrefixObjectAccessor<TParentData<TParentData>, []> : TParentData extends string | number | bigint | boolean ? "" : never;
The field name.
Defined in#
packages/form-core/src/FieldApi.ts:451
options#
options: FieldApiOptions<TParentData, TName, TFieldValidator, TFormValidator, TData>;
The field options.
Defined in#
packages/form-core/src/FieldApi.ts:455
store#
store: Derived<FieldState<TData>, readonly any[]>;
The field state store.
Defined in#
packages/form-core/src/FieldApi.ts:465
timeoutIds#
timeoutIds: Record<ValidationCause, null | Timeout>;
Defined in#
packages/form-core/src/FieldApi.ts:472
Accessors#
state#
Get Signature#
get state(): FieldState<TData>
The current field state.
Returns#
FieldState<TData>
Defined in#
packages/form-core/src/FieldApi.ts:469
Methods#
getInfo()#
getInfo(): FieldInfo<TParentData, TFormValidator>
Gets the field information object.
Returns#
FieldInfo<TParentData, TFormValidator>
Defined in#
packages/form-core/src/FieldApi.ts:672
getMeta()#
getMeta(): FieldMeta
Returns#
Defined in#
packages/form-core/src/FieldApi.ts:661
getValue()#
getValue(): TData
Gets the current field value.
Returns#
TData
Deprecated#
Use field.state.value instead.
Defined in#
packages/form-core/src/FieldApi.ts:643
handleBlur()#
handleBlur(): void
Handles the blur event.
Returns#
void
Defined in#
packages/form-core/src/FieldApi.ts:1024
handleChange()#
handleChange(updater): void
Handles the change event.
Parameters#
updater#
Updater<TData>
Returns#
void
Defined in#
packages/form-core/src/FieldApi.ts:1017
insertValue()#
insertValue(
index,
value,
opts?): Promise<void>
Inserts a value at the specified index, shifting the subsequent values to the right.
Parameters#
index#
number
value#
TData extends any[] ? TData<TData>[number] : never
opts?#
UpdateMetaOptions
Returns#
Promise<void>
Defined in#
packages/form-core/src/FieldApi.ts:685
mount()#
mount(): () => void
Mounts the field instance to the form.
Returns#
Function
Returns#
void
Defined in#
packages/form-core/src/FieldApi.ts:567
moveValue()#
moveValue(
aIndex,
bIndex,
opts?): void
Moves the value at the first specified index to the second specified index.
Parameters#
aIndex#
number
bIndex#
number
opts?#
UpdateMetaOptions
Returns#
void
Defined in#
packages/form-core/src/FieldApi.ts:715
pushValue()#
pushValue(value, opts?): void
Pushes a new value to the field.
Parameters#
value#
TData extends any[] ? TData<TData>[number] : never
opts?#
UpdateMetaOptions
Returns#
void
Defined in#
packages/form-core/src/FieldApi.ts:677
removeValue()#
removeValue(index, opts?): Promise<void>
Removes a value at the specified index.
Parameters#
index#
number
opts?#
UpdateMetaOptions
Returns#
Promise<void>
Defined in#
packages/form-core/src/FieldApi.ts:703
replaceValue()#
replaceValue(
index,
value,
opts?): Promise<void>
Replaces a value at the specified index.
Parameters#
index#
number
value#
TData extends any[] ? TData<TData>[number] : never
opts?#
UpdateMetaOptions
Returns#
Promise<void>
Defined in#
packages/form-core/src/FieldApi.ts:694
setErrorMap()#
setErrorMap(errorMap): void
Updates the field's errorMap
Parameters#
errorMap#
ValidationErrorMap
Returns#
void
Defined in#
packages/form-core/src/FieldApi.ts:1044
setMeta()#
setMeta(updater): void
Sets the field metadata.
Parameters#
updater#
Returns#
void
Defined in#
packages/form-core/src/FieldApi.ts:666
setValue()#
setValue(updater, options?): void
Sets the field value and run the change validator.
Parameters#
updater#
Updater<TData>
options?#
UpdateMetaOptions
Returns#
void
Defined in#
packages/form-core/src/FieldApi.ts:650
swapValues()#
swapValues(
aIndex,
bIndex,
opts?): void
Swaps the values at the specified indices.
Parameters#
aIndex#
number
bIndex#
number
opts?#
UpdateMetaOptions
Returns#
void
Defined in#
packages/form-core/src/FieldApi.ts:709
update()#
update(opts): void
Updates the field instance with new options.
Parameters#
opts#
FieldApiOptions<TParentData, TName, TFieldValidator, TFormValidator, TData>
Returns#
void
Defined in#
packages/form-core/src/FieldApi.ts:606
validate()#
validate(cause): ValidationError[] | Promise<ValidationError[]>
Validates the field value.
Parameters#
cause#
ValidationCause
Returns#
ValidationError[] | Promise<ValidationError[]>