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.
• 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>
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>
Initializes a new FieldApi instance.
• opts: FieldApiOptions<TParentData, TName, TFieldValidator, TFormValidator, TData>
FieldApi<TParentData, TName, TFieldValidator, TFormValidator, TData>
packages/form-core/src/FieldApi.ts:440
form: FormApi<TParentData, TFormValidator>;
form: FormApi<TParentData, TFormValidator>;
A reference to the form API instance.
packages/form-core/src/FieldApi.ts:402
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;
The field name.
packages/form-core/src/FieldApi.ts:412
options: FieldApiOptions<TParentData, TName, TFieldValidator, TFormValidator, TData>;
options: FieldApiOptions<TParentData, TName, TFieldValidator, TFormValidator, TData>;
The field options.
packages/form-core/src/FieldApi.ts:416
state: FieldState<TData>;
state: FieldState<TData>;
The current field state.
packages/form-core/src/FieldApi.ts:430
store: Store<FieldState<TData>, (cb) => FieldState<TData>>;
store: Store<FieldState<TData>, (cb) => FieldState<TData>>;
The field state store.
packages/form-core/src/FieldApi.ts:426
timeoutIds: Record<ValidationCause, null | Timeout>;
timeoutIds: Record<ValidationCause, null | Timeout>;
packages/form-core/src/FieldApi.ts:435
getInfo(): FieldInfo<TParentData, TFormValidator>
getInfo(): FieldInfo<TParentData, TFormValidator>
Gets the field information object.
FieldInfo<TParentData, TFormValidator>
packages/form-core/src/FieldApi.ts:658
getMeta(): FieldMeta
getMeta(): FieldMeta
Gets the current field metadata.
packages/form-core/src/FieldApi.ts:636
getValue(): TData
getValue(): TData
Gets the current field value.
TData
Use field.state.value instead.
packages/form-core/src/FieldApi.ts:616
handleBlur(): void
handleBlur(): void
Handles the blur event.
void
packages/form-core/src/FieldApi.ts:1010
handleChange(updater): void
handleChange(updater): void
Handles the change event.
• updater: Updater<TData>
void
packages/form-core/src/FieldApi.ts:1003
insertValue(
index,
value,
opts?): Promise<void>
insertValue(
index,
value,
opts?): Promise<void>
Inserts a value at the specified index, shifting the subsequent values to the right.
• index: number
• value: TData extends any[] ? TData<TData>[number] : never
• opts?: UpdateMetaOptions
Promise<void>
packages/form-core/src/FieldApi.ts:671
mount(): () => void
mount(): () => void
Mounts the field instance to the form.
Function
void
packages/form-core/src/FieldApi.ts:531
moveValue(
aIndex,
bIndex,
opts?): void
moveValue(
aIndex,
bIndex,
opts?): void
Moves the value at the first specified index to the second specified index.
• aIndex: number
• bIndex: number
• opts?: UpdateMetaOptions
void
packages/form-core/src/FieldApi.ts:701
pushValue(value, opts?): void
pushValue(value, opts?): void
Pushes a new value to the field.
• value: TData extends any[] ? TData<TData>[number] : never
• opts?: UpdateMetaOptions
void
packages/form-core/src/FieldApi.ts:663
removeValue(index, opts?): Promise<void>
removeValue(index, opts?): Promise<void>
Removes a value at the specified index.
• index: number
• opts?: UpdateMetaOptions
Promise<void>
packages/form-core/src/FieldApi.ts:689
replaceValue(
index,
value,
opts?): Promise<void>
replaceValue(
index,
value,
opts?): Promise<void>
Replaces a value at the specified index.
• index: number
• value: TData extends any[] ? TData<TData>[number] : never
• opts?: UpdateMetaOptions
Promise<void>
packages/form-core/src/FieldApi.ts:680
setErrorMap(errorMap): void
setErrorMap(errorMap): void
Updates the field's errorMap
• errorMap: ValidationErrorMap
void
packages/form-core/src/FieldApi.ts:1025
setMeta(updater): void
setMeta(updater): void
Sets the field metadata.
void
packages/form-core/src/FieldApi.ts:652
setValue(updater, options?): void
setValue(updater, options?): void
Sets the field value and run the change validator.
• updater: Updater<TData>
• options?: UpdateMetaOptions
void
packages/form-core/src/FieldApi.ts:623
swapValues(
aIndex,
bIndex,
opts?): void
swapValues(
aIndex,
bIndex,
opts?): void
Swaps the values at the specified indices.
• aIndex: number
• bIndex: number
• opts?: UpdateMetaOptions
void
packages/form-core/src/FieldApi.ts:695
update(opts): void
update(opts): void
Updates the field instance with new options.
• opts: FieldApiOptions<TParentData, TName, TFieldValidator, TFormValidator, TData>
void
packages/form-core/src/FieldApi.ts:579
validate(cause): ValidationError[] | Promise<ValidationError[]>
validate(cause): ValidationError[] | Promise<ValidationError[]>
Validates the field value.
• cause: ValidationCause
ValidationError[] | Promise<ValidationError[]>
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.