TanStackForm v0
Auto

FieldApi

Class: FieldApi<TParentData, TName, TFieldValidator, TFormValidator, TData>

Defined in: packages/form-core/src/FieldApi.ts:427

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>
new FieldApi<TParentData, TName, TFieldValidator, TFormValidator, TData>(opts): FieldApi<TParentData, TName, TFieldValidator, TFormValidator, TData>

Defined in: packages/form-core/src/FieldApi.ts:477

Initializes a new FieldApi instance.

Parameters

opts

FieldApiOptions<TParentData, TName, TFieldValidator, TFormValidator, TData>

Returns

FieldApi<TParentData, TName, TFieldValidator, TFormValidator, TData>

Properties

form

ts
form: FormApi<TParentData, TFormValidator>;
form: FormApi<TParentData, TFormValidator>;

Defined in: packages/form-core/src/FieldApi.ts:441

A reference to the form API instance.


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;
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;

Defined in: packages/form-core/src/FieldApi.ts:451

The field name.


options

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

Defined in: packages/form-core/src/FieldApi.ts:455

The field options.


store

ts
store: Derived<FieldState<TData>>;
store: Derived<FieldState<TData>>;

Defined in: packages/form-core/src/FieldApi.ts:465

The field state store.


timeoutIds

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

Defined in: packages/form-core/src/FieldApi.ts:472

Accessors

state

Get Signature

ts
get state(): FieldState<TData>
get state(): FieldState<TData>

Defined in: packages/form-core/src/FieldApi.ts:469

The current field state.

Returns

FieldState<TData>

Methods

getInfo()

ts
getInfo(): FieldInfo<TParentData, TFormValidator>
getInfo(): FieldInfo<TParentData, TFormValidator>

Defined in: packages/form-core/src/FieldApi.ts:673

Gets the field information object.

Returns

FieldInfo<TParentData, TFormValidator>


getMeta()

ts
getMeta(): FieldMeta
getMeta(): FieldMeta

Defined in: packages/form-core/src/FieldApi.ts:662

Returns

FieldMeta


getValue()

ts
getValue(): TData
getValue(): TData

Defined in: packages/form-core/src/FieldApi.ts:644

Gets the current field value.

Returns

TData

Deprecated

Use field.state.value instead.


handleBlur()

ts
handleBlur(): void
handleBlur(): void

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

Handles the blur event.

Returns

void


handleChange()

ts
handleChange(updater): void
handleChange(updater): void

Defined in: packages/form-core/src/FieldApi.ts:1018

Handles the change event.

Parameters

updater

Updater<TData>

Returns

void


insertValue()

ts
insertValue(
   index, 
   value, 
opts?): Promise<void>
insertValue(
   index, 
   value, 
opts?): Promise<void>

Defined in: packages/form-core/src/FieldApi.ts:686

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>


mount()

ts
mount(): () => void
mount(): () => void

Defined in: packages/form-core/src/FieldApi.ts:567

Mounts the field instance to the form.

Returns

Function

Returns

void


moveValue()

ts
moveValue(
   aIndex, 
   bIndex, 
   opts?): void
moveValue(
   aIndex, 
   bIndex, 
   opts?): void

Defined in: packages/form-core/src/FieldApi.ts:716

Moves the value at the first specified index to the second specified index.

Parameters

aIndex

number

bIndex

number

opts?

UpdateMetaOptions

Returns

void


pushValue()

ts
pushValue(value, opts?): void
pushValue(value, opts?): void

Defined in: packages/form-core/src/FieldApi.ts:678

Pushes a new value to the field.

Parameters

value

TData extends any[] ? TData<TData>[number] : never

opts?

UpdateMetaOptions

Returns

void


removeValue()

ts
removeValue(index, opts?): Promise<void>
removeValue(index, opts?): Promise<void>

Defined in: packages/form-core/src/FieldApi.ts:704

Removes a value at the specified index.

Parameters

index

number

opts?

UpdateMetaOptions

Returns

Promise<void>


replaceValue()

ts
replaceValue(
   index, 
   value, 
opts?): Promise<void>
replaceValue(
   index, 
   value, 
opts?): Promise<void>

Defined in: packages/form-core/src/FieldApi.ts:695

Replaces a value at the specified index.

Parameters

index

number

value

TData extends any[] ? TData<TData>[number] : never

opts?

UpdateMetaOptions

Returns

Promise<void>


setErrorMap()

ts
setErrorMap(errorMap): void
setErrorMap(errorMap): void

Defined in: packages/form-core/src/FieldApi.ts:1045

Updates the field's errorMap

Parameters

errorMap

ValidationErrorMap

Returns

void


setMeta()

ts
setMeta(updater): void
setMeta(updater): void

Defined in: packages/form-core/src/FieldApi.ts:667

Sets the field metadata.

Parameters

updater

Updater<FieldMeta>

Returns

void


setValue()

ts
setValue(updater, options?): void
setValue(updater, options?): void

Defined in: packages/form-core/src/FieldApi.ts:651

Sets the field value and run the change validator.

Parameters

updater

Updater<TData>

options?

UpdateMetaOptions

Returns

void


swapValues()

ts
swapValues(
   aIndex, 
   bIndex, 
   opts?): void
swapValues(
   aIndex, 
   bIndex, 
   opts?): void

Defined in: packages/form-core/src/FieldApi.ts:710

Swaps the values at the specified indices.

Parameters

aIndex

number

bIndex

number

opts?

UpdateMetaOptions

Returns

void


update()

ts
update(opts): void
update(opts): void

Defined in: packages/form-core/src/FieldApi.ts:606

Updates the field instance with new options.

Parameters

opts

FieldApiOptions<TParentData, TName, TFieldValidator, TFormValidator, TData>

Returns

void


validate()

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

Defined in: packages/form-core/src/FieldApi.ts:990

Validates the field value.

Parameters

cause

ValidationCause

Returns

| ValidationError[] | Promise<ValidationError[]>

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.