A class representing the Form API. It handles the logic and interactions with the form state.
Normally, you will not need to create a new FormApi instance directly. Instead, you will use a framework hook/function like useForm or createForm 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 FormApi constructor.
• TFormData
• TFormValidator extends Validator<TFormData, unknown> | undefined = undefined
new FormApi<TFormData, TFormValidator>(opts?): FormApi<TFormData, TFormValidator>
new FormApi<TFormData, TFormValidator>(opts?): FormApi<TFormData, TFormValidator>
Constructs a new FormApi instance with the given form options.
• opts?: FormOptions<TFormData, TFormValidator>
FormApi<TFormData, TFormValidator>
packages/form-core/src/FormApi.ts:386
fieldInfo: Record<unknown extends TFormData ? string : TFormData extends readonly any[] & IsTuple<TFormData> ? PrefixTupleAccessor<TFormData<TFormData>, AllowedIndexes<TFormData<TFormData>, never>, []> : TFormData extends any[] ? PrefixArrayAccessor<TFormData<TFormData>, [any]> : TFormData extends Date ? never : TFormData extends object ? PrefixObjectAccessor<TFormData<TFormData>, []> : TFormData extends string | number | bigint | boolean ? "" : never, FieldInfo<TFormData, TFormValidator>>;
fieldInfo: Record<unknown extends TFormData ? string : TFormData extends readonly any[] & IsTuple<TFormData> ? PrefixTupleAccessor<TFormData<TFormData>, AllowedIndexes<TFormData<TFormData>, never>, []> : TFormData extends any[] ? PrefixArrayAccessor<TFormData<TFormData>, [any]> : TFormData extends Date ? never : TFormData extends object ? PrefixObjectAccessor<TFormData<TFormData>, []> : TFormData extends string | number | bigint | boolean ? "" : never, FieldInfo<TFormData, TFormValidator>>;
A record of field information for each field in the form.
packages/form-core/src/FormApi.ts:375
options: FormOptions<TFormData, TFormValidator> = {};
options: FormOptions<TFormData, TFormValidator> = {};
The options for the form.
packages/form-core/src/FormApi.ts:359
state: FormState<TFormData>;
state: FormState<TFormData>;
The current state of the form.
Note: Do not use state directly, as it is not reactive. Please use form.useStore() utility to subscribe to state
packages/form-core/src/FormApi.ts:371
store: Store<FormState<TFormData>, (cb) => FormState<TFormData>>;
store: Store<FormState<TFormData>, (cb) => FormState<TFormData>>;
A TanStack Store instance that keeps track of the form's state.
packages/form-core/src/FormApi.ts:363
deleteField<TField>(field): void
deleteField<TField>(field): void
• TField extends string | number
• field: TField
void
packages/form-core/src/FormApi.ts:1117
getFieldInfo<TField>(field): FieldInfo<TFormData, TFormValidator>
getFieldInfo<TField>(field): FieldInfo<TFormData, TFormValidator>
Gets the field info of the specified field.
• TField extends string | number
• field: TField
FieldInfo<TFormData, TFormValidator>
packages/form-core/src/FormApi.ts:1028
getFieldMeta<TField>(field): undefined | FieldMeta
getFieldMeta<TField>(field): undefined | FieldMeta
Gets the metadata of the specified field.
• TField extends string | number
• field: TField
undefined | FieldMeta
packages/form-core/src/FormApi.ts:1019
getFieldValue<TField>(field): DeepValue<TFormData, TField, IsNullable<TFormData>>
getFieldValue<TField>(field): DeepValue<TFormData, TField, IsNullable<TFormData>>
Gets the value of the specified field.
• TField extends string | number
• field: TField
DeepValue<TFormData, TField, IsNullable<TFormData>>
packages/form-core/src/FormApi.ts:1012
handleSubmit(): Promise<void>
handleSubmit(): Promise<void>
Handles the form submission, performs validation, and calls the appropriate onSubmit or onInvalidSubmit callbacks.
Promise<void>
packages/form-core/src/FormApi.ts:952
insertFieldValue<TField>(
field,
index,
value,
opts?): Promise<void>
insertFieldValue<TField>(
field,
index,
value,
opts?): Promise<void>
Inserts a value into an array field at the specified index, shifting the subsequent values to the right.
• TField extends string | number
• field: TField
• index: number
• value: DeepValue<TFormData, TField, IsNullable<TFormData>> extends any[] ? any[] & DeepValue<TFormData, TField, IsNullable<TFormData>>[number] : never
• opts?: UpdateMetaOptions
Promise<void>
packages/form-core/src/FormApi.ts:1149
mount(): void
mount(): void
void
packages/form-core/src/FormApi.ts:513
moveFieldValues<TField>(
field,
index1,
index2,
opts?): void
moveFieldValues<TField>(
field,
index1,
index2,
opts?): void
Moves the value at the first specified index to the second specified index within an array field.
• TField extends string | number
• field: TField
• index1: number
• index2: number
• opts?: UpdateMetaOptions
void
packages/form-core/src/FormApi.ts:1267
pushFieldValue<TField>(
field,
value,
opts?): void
pushFieldValue<TField>(
field,
value,
opts?): void
Pushes a value into an array field.
• TField extends string | number
• field: TField
• value: DeepValue<TFormData, TField, IsNullable<TFormData>> extends any[] ? any[] & DeepValue<TFormData, TField, IsNullable<TFormData>>[number] : never
• opts?: UpdateMetaOptions
void
packages/form-core/src/FormApi.ts:1131
removeFieldValue<TField>(
field,
index,
opts?): Promise<void>
removeFieldValue<TField>(
field,
index,
opts?): Promise<void>
Removes a value from an array field at the specified index.
• TField extends string | number
• field: TField
• index: number
• opts?: UpdateMetaOptions
Promise<void>
packages/form-core/src/FormApi.ts:1202
replaceFieldValue<TField>(
field,
index,
value,
opts?): Promise<void>
replaceFieldValue<TField>(
field,
index,
value,
opts?): Promise<void>
Replaces a value into an array field at the specified index.
• TField extends string | number
• field: TField
• index: number
• value: DeepValue<TFormData, TField, IsNullable<TFormData>> extends any[] ? any[] & DeepValue<TFormData, TField, IsNullable<TFormData>>[number] : never
• opts?: UpdateMetaOptions
Promise<void>
packages/form-core/src/FormApi.ts:1176
reset(values?, opts?): void
reset(values?, opts?): void
Resets the form state to the default values. If values are provided, the form will be reset to those values instead and the default values will be updated.
• values?: TFormData
Optional values to reset the form to.
• opts?
Optional options to control the reset behavior.
• opts.keepDefaultValues?: boolean
void
packages/form-core/src/FormApi.ts:580
resetFieldMeta<TField>(fieldMeta): Record<TField, FieldMeta>
resetFieldMeta<TField>(fieldMeta): Record<TField, FieldMeta>
• TField extends string | number
• fieldMeta: Record<TField, FieldMeta>
Record<TField, FieldMeta>
packages/form-core/src/FormApi.ts:1062
setErrorMap(errorMap): void
setErrorMap(errorMap): void
Updates the form's errorMap
• errorMap: ValidationErrorMap
void
packages/form-core/src/FormApi.ts:1291
setFieldMeta<TField>(field, updater): void
setFieldMeta<TField>(field, updater): void
Updates the metadata of the specified field.
• TField extends string | number
• field: TField
void
packages/form-core/src/FormApi.ts:1047
setFieldValue<TField>(
field,
updater,
opts?): void
setFieldValue<TField>(
field,
updater,
opts?): void
Sets the value of the specified field and optionally updates the touched state.
• TField extends string | number
• field: TField
• updater: Updater<DeepValue<TFormData, TField, IsNullable<TFormData>>>
• opts?: UpdateMetaOptions
void
packages/form-core/src/FormApi.ts:1086
swapFieldValues<TField>(
field,
index1,
index2,
opts?): void
swapFieldValues<TField>(
field,
index1,
index2,
opts?): void
Swaps the values at the specified indices within an array field.
• TField extends string | number
• field: TField
• index1: number
• index2: number
• opts?: UpdateMetaOptions
void
packages/form-core/src/FormApi.ts:1241
update(options?): void
update(options?): void
Updates the form options and form state.
• options?: FormOptions<TFormData, TFormValidator>
void
packages/form-core/src/FormApi.ts:536
validateAllFields(cause): Promise<ValidationError[]>
validateAllFields(cause): Promise<ValidationError[]>
Validates all fields in the form using the correct handlers for a given validation type.
• cause: ValidationCause
Promise<ValidationError[]>
packages/form-core/src/FormApi.ts:606
validateArrayFieldsStartingFrom<TField>(
field,
index,
cause): Promise<ValidationError[]>
validateArrayFieldsStartingFrom<TField>(
field,
index,
cause): Promise<ValidationError[]>
Validates the children of a specified array in the form starting from a given index until the end using the correct handlers for a given validation type.
• TField extends string | number
• field: TField
• index: number
• cause: ValidationCause
Promise<ValidationError[]>
packages/form-core/src/FormApi.ts:640
validateField<TField>(field, cause): ValidationError[] | Promise<ValidationError[]>
validateField<TField>(field, cause): ValidationError[] | Promise<ValidationError[]>
Validates a specified field in the form using the correct handlers for a given validation type.
• TField extends string | number
• field: TField
• cause: ValidationCause
ValidationError[] | Promise<ValidationError[]>
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.