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.
FieldApiOptions<TParentData, TName, TFieldValidator, TFormValidator, TData>
FieldApi<TParentData, TName, TFieldValidator, TFormValidator, TData>
packages/form-core/src/FieldApi.ts:474
form: FormApi<TParentData, TFormValidator>;
form: FormApi<TParentData, TFormValidator>;
A reference to the form API instance.
packages/form-core/src/FieldApi.ts:436
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:446
options: FieldApiOptions<TParentData, TName, TFieldValidator, TFormValidator, TData>;
options: FieldApiOptions<TParentData, TName, TFieldValidator, TFormValidator, TData>;
The field options.
packages/form-core/src/FieldApi.ts:450
state: FieldState<TData>;
state: FieldState<TData>;
The current field state.
packages/form-core/src/FieldApi.ts:464
store: Store<FieldState<TData>, (cb) => FieldState<TData>>;
store: Store<FieldState<TData>, (cb) => FieldState<TData>>;
The field state store.
packages/form-core/src/FieldApi.ts:460
timeoutIds: Record<ValidationCause, null | Timeout>;
timeoutIds: Record<ValidationCause, null | Timeout>;
packages/form-core/src/FieldApi.ts:469
getInfo(): FieldInfo<TParentData, TFormValidator>
getInfo(): FieldInfo<TParentData, TFormValidator>
Gets the field information object.
FieldInfo<TParentData, TFormValidator>
packages/form-core/src/FieldApi.ts:713
getMeta(): FieldMeta
getMeta(): FieldMeta
Gets the current field metadata.
packages/form-core/src/FieldApi.ts:691
getValue(): TData
getValue(): TData
Gets the current field value.
TData
Use field.state.value instead.
packages/form-core/src/FieldApi.ts:665
handleBlur(): void
handleBlur(): void
Handles the blur event.
void
packages/form-core/src/FieldApi.ts:1065
handleChange(updater): void
handleChange(updater): void
Handles the change event.
Updater<TData>
void
packages/form-core/src/FieldApi.ts:1058
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.
number
TData extends any[] ? TData<TData>[number] : never
UpdateMetaOptions
Promise<void>
packages/form-core/src/FieldApi.ts:726
mount(): () => void
mount(): () => void
Mounts the field instance to the form.
Function
void
packages/form-core/src/FieldApi.ts:575
moveValue(
aIndex,
bIndex,
opts?): void
moveValue(
aIndex,
bIndex,
opts?): void
Moves the value at the first specified index to the second specified index.
number
number
UpdateMetaOptions
void
packages/form-core/src/FieldApi.ts:756
pushValue(value, opts?): void
pushValue(value, opts?): void
Pushes a new value to the field.
TData extends any[] ? TData<TData>[number] : never
UpdateMetaOptions
void
packages/form-core/src/FieldApi.ts:718
removeValue(index, opts?): Promise<void>
removeValue(index, opts?): Promise<void>
Removes a value at the specified index.
number
UpdateMetaOptions
Promise<void>
packages/form-core/src/FieldApi.ts:744
replaceValue(
index,
value,
opts?): Promise<void>
replaceValue(
index,
value,
opts?): Promise<void>
Replaces a value at the specified index.
number
TData extends any[] ? TData<TData>[number] : never
UpdateMetaOptions
Promise<void>
packages/form-core/src/FieldApi.ts:735
setErrorMap(errorMap): void
setErrorMap(errorMap): void
Updates the field's errorMap
ValidationErrorMap
void
packages/form-core/src/FieldApi.ts:1085
setMeta(updater): void
setMeta(updater): void
Sets the field metadata.
void
packages/form-core/src/FieldApi.ts:707
setValue(updater, options?): void
setValue(updater, options?): void
Sets the field value and run the change validator.
Updater<TData>
UpdateMetaOptions
void
packages/form-core/src/FieldApi.ts:672
swapValues(
aIndex,
bIndex,
opts?): void
swapValues(
aIndex,
bIndex,
opts?): void
Swaps the values at the specified indices.
number
number
UpdateMetaOptions
void
packages/form-core/src/FieldApi.ts:750
update(opts): void
update(opts): void
Updates the field instance with new options.
FieldApiOptions<TParentData, TName, TFieldValidator, TFormValidator, TData>
void
packages/form-core/src/FieldApi.ts:628
validate(cause): ValidationError[] | Promise<ValidationError[]>
validate(cause): ValidationError[] | Promise<ValidationError[]>
Validates the field value.
ValidationCause
ValidationError[] | Promise<ValidationError[]>
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.