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.
FormOptions<TFormData, TFormValidator>
FormApi<TFormData, TFormValidator>
packages/form-core/src/FormApi.ts:389
baseStore: Store<BaseFormState<TFormData>, (cb) => BaseFormState<TFormData>>;
baseStore: Store<BaseFormState<TFormData>, (cb) => BaseFormState<TFormData>>;
packages/form-core/src/FormApi.ts:368
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:374
fieldMetaDerived: Derived<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, FieldMeta>, readonly any[]>;
fieldMetaDerived: Derived<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, FieldMeta>, readonly any[]>;
packages/form-core/src/FormApi.ts:369
options: FormOptions<TFormData, TFormValidator> = {};
options: FormOptions<TFormData, TFormValidator> = {};
The options for the form.
packages/form-core/src/FormApi.ts:367
store: Derived<FormState<TFormData>, readonly any[]>;
store: Derived<FormState<TFormData>, readonly any[]>;
packages/form-core/src/FormApi.ts:370
get state(): FormState<TFormData>
get state(): FormState<TFormData>
FormState<TFormData>
packages/form-core/src/FormApi.ts:377
deleteField<TField>(field): void
deleteField<TField>(field): void
• TField extends string | number
TField
void
packages/form-core/src/FormApi.ts:1182
getFieldInfo<TField>(field): FieldInfo<TFormData, TFormValidator>
getFieldInfo<TField>(field): FieldInfo<TFormData, TFormValidator>
Gets the field info of the specified field.
• TField extends string | number
TField
FieldInfo<TFormData, TFormValidator>
packages/form-core/src/FormApi.ts:1091
getFieldMeta<TField>(field): undefined | FieldMeta
getFieldMeta<TField>(field): undefined | FieldMeta
Gets the metadata of the specified field.
• TField extends string | number
TField
undefined | FieldMeta
packages/form-core/src/FormApi.ts:1082
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
TField
DeepValue<TFormData, TField, IsNullable<TFormData>>
packages/form-core/src/FormApi.ts:1075
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:1016
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
TField
number
DeepValue<TFormData, TField, IsNullable<TFormData>> extends any[] ? any[] & DeepValue<TFormData, TField, IsNullable<TFormData>>[number] : never
UpdateMetaOptions
Promise<void>
packages/form-core/src/FormApi.ts:1214
mount(): () => void
mount(): () => void
Function
void
packages/form-core/src/FormApi.ts:595
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
TField
number
number
UpdateMetaOptions
void
packages/form-core/src/FormApi.ts:1332
pushFieldValue<TField>(
field,
value,
opts?): void
pushFieldValue<TField>(
field,
value,
opts?): void
Pushes a value into an array field.
• TField extends string | number
TField
DeepValue<TFormData, TField, IsNullable<TFormData>> extends any[] ? any[] & DeepValue<TFormData, TField, IsNullable<TFormData>>[number] : never
UpdateMetaOptions
void
packages/form-core/src/FormApi.ts:1196
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
TField
number
UpdateMetaOptions
Promise<void>
packages/form-core/src/FormApi.ts:1267
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
TField
number
DeepValue<TFormData, TField, IsNullable<TFormData>> extends any[] ? any[] & DeepValue<TFormData, TField, IsNullable<TFormData>>[number] : never
UpdateMetaOptions
Promise<void>
packages/form-core/src/FormApi.ts:1241
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.
TFormData
Optional values to reset the form to.
Optional options to control the reset behavior.
boolean
void
packages/form-core/src/FormApi.ts:656
resetFieldMeta<TField>(fieldMeta): Record<TField, FieldMeta>
resetFieldMeta<TField>(fieldMeta): Record<TField, FieldMeta>
• TField extends string | number
Record<TField, FieldMeta>
Record<TField, FieldMeta>
packages/form-core/src/FormApi.ts:1128
setErrorMap(errorMap): void
setErrorMap(errorMap): void
Updates the form's errorMap
ValidationErrorMap
void
packages/form-core/src/FormApi.ts:1356
setFieldMeta<TField>(field, updater): void
setFieldMeta<TField>(field, updater): void
Updates the metadata of the specified field.
• TField extends string | number
TField
void
packages/form-core/src/FormApi.ts:1110
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
TField
Updater<DeepValue<TFormData, TField, IsNullable<TFormData>>>
UpdateMetaOptions
void
packages/form-core/src/FormApi.ts:1152
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
TField
number
number
UpdateMetaOptions
void
packages/form-core/src/FormApi.ts:1306
update(options?): void
update(options?): void
Updates the form options and form state.
FormOptions<TFormData, TFormValidator>
void
packages/form-core/src/FormApi.ts:612
validateAllFields(cause): Promise<ValidationError[]>
validateAllFields(cause): Promise<ValidationError[]>
Validates form and all fields in using the correct handlers for a given validation cause.
ValidationCause
Promise<ValidationError[]>
packages/form-core/src/FormApi.ts:682
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
TField
number
ValidationCause
Promise<ValidationError[]>
packages/form-core/src/FormApi.ts:710
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
TField
ValidationCause
ValidationError[] | Promise<ValidationError[]>
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.