FieldApi

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()

ts
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:440

Properties

form

ts
form: FormApi<TParentData, TFormValidator>;

A reference to the form API instance.

Defined in

packages/form-core/src/FieldApi.ts:402


name

ts
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:412


options

ts
options: FieldApiOptions<TParentData, TName, TFieldValidator, TFormValidator, TData>;

The field options.

Defined in

packages/form-core/src/FieldApi.ts:416


state

ts
state: FieldState<TData>;

The current field state.

Defined in

packages/form-core/src/FieldApi.ts:430


store

ts
store: Store<FieldState<TData>, (cb) => FieldState<TData>>;

The field state store.

Defined in

packages/form-core/src/FieldApi.ts:426


timeoutIds

ts
timeoutIds: Record<ValidationCause, null | Timeout>;

Defined in

packages/form-core/src/FieldApi.ts:435

Methods

getInfo()

ts
getInfo(): FieldInfo<TParentData, TFormValidator>

Gets the field information object.

Returns

FieldInfo<TParentData, TFormValidator>

Defined in

packages/form-core/src/FieldApi.ts:658


getMeta()

ts
getMeta(): FieldMeta

Gets the current field metadata.

Returns

FieldMeta

Defined in

packages/form-core/src/FieldApi.ts:636


getValue()

ts
getValue(): TData

Gets the current field value.

Returns

TData

Deprecated

Use field.state.value instead.

Defined in

packages/form-core/src/FieldApi.ts:616


handleBlur()

ts
handleBlur(): void

Handles the blur event.

Returns

void

Defined in

packages/form-core/src/FieldApi.ts:1010


handleChange()

ts
handleChange(updater): void

Handles the change event.

Parameters

updater: Updater<TData>

Returns

void

Defined in

packages/form-core/src/FieldApi.ts:1003


insertValue()

ts
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:671


mount()

ts
mount(): () => void

Mounts the field instance to the form.

Returns

Function

Returns

void

Defined in

packages/form-core/src/FieldApi.ts:531


moveValue()

ts
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:701


pushValue()

ts
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:663


removeValue()

ts
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:689


replaceValue()

ts
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:680


setErrorMap()

ts
setErrorMap(errorMap): void

Updates the field's errorMap

Parameters

errorMap: ValidationErrorMap

Returns

void

Defined in

packages/form-core/src/FieldApi.ts:1025


setMeta()

ts
setMeta(updater): void

Sets the field metadata.

Parameters

updater: Updater<FieldMeta>

Returns

void

Defined in

packages/form-core/src/FieldApi.ts:652


setValue()

ts
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:623


swapValues()

ts
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:695


update()

ts
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:579


validate()

ts
validate(cause): ValidationError[] | Promise<ValidationError[]>

Validates the field value.

Parameters

cause: ValidationCause

Returns

ValidationError[] | Promise<ValidationError[]>

Defined in

packages/form-core/src/FieldApi.ts:975

Subscribe to Bytes

Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.

Bytes

No spam. Unsubscribe at any time.

scarf analytics