@tanstack/form-core 1.14.0 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const store = require("@tanstack/store");
4
+ const utils = require("./utils.cjs");
5
+ class FieldGroupApi {
6
+ /**
7
+ * Constructs a new `FieldGroupApi` instance with the given form options.
8
+ */
9
+ constructor(opts) {
10
+ this.getFormFieldName = (subfield) => {
11
+ if (typeof this.fieldsMap === "string") {
12
+ return utils.concatenatePaths(this.fieldsMap, subfield);
13
+ }
14
+ const firstAccessor = utils.makePathArray(subfield)[0];
15
+ if (typeof firstAccessor !== "string") {
16
+ return "";
17
+ }
18
+ const restOfPath = subfield.slice(firstAccessor.length);
19
+ const formMappedPath = (
20
+ // TFields is either a string or this. See guard above.
21
+ this.fieldsMap[firstAccessor]
22
+ );
23
+ return utils.concatenatePaths(formMappedPath, restOfPath);
24
+ };
25
+ this.mount = () => {
26
+ const cleanup = this.store.mount();
27
+ return cleanup;
28
+ };
29
+ this.validateArrayFieldsStartingFrom = async (field, index, cause) => {
30
+ return this.form.validateArrayFieldsStartingFrom(
31
+ this.getFormFieldName(field),
32
+ index,
33
+ cause
34
+ );
35
+ };
36
+ this.validateField = (field, cause) => {
37
+ return this.form.validateField(this.getFormFieldName(field), cause);
38
+ };
39
+ this.getFieldValue = (field) => {
40
+ return this.form.getFieldValue(this.getFormFieldName(field));
41
+ };
42
+ this.getFieldMeta = (field) => {
43
+ return this.form.getFieldMeta(this.getFormFieldName(field));
44
+ };
45
+ this.setFieldMeta = (field, updater) => {
46
+ return this.form.setFieldMeta(this.getFormFieldName(field), updater);
47
+ };
48
+ this.setFieldValue = (field, updater, opts2) => {
49
+ return this.form.setFieldValue(
50
+ this.getFormFieldName(field),
51
+ updater,
52
+ opts2
53
+ );
54
+ };
55
+ this.deleteField = (field) => {
56
+ return this.form.deleteField(this.getFormFieldName(field));
57
+ };
58
+ this.pushFieldValue = (field, value, opts2) => {
59
+ return this.form.pushFieldValue(
60
+ this.getFormFieldName(field),
61
+ // since unknown doesn't extend an array, it types `value` as never.
62
+ value,
63
+ opts2
64
+ );
65
+ };
66
+ this.insertFieldValue = async (field, index, value, opts2) => {
67
+ return this.form.insertFieldValue(
68
+ this.getFormFieldName(field),
69
+ index,
70
+ // since unknown doesn't extend an array, it types `value` as never.
71
+ value,
72
+ opts2
73
+ );
74
+ };
75
+ this.replaceFieldValue = async (field, index, value, opts2) => {
76
+ return this.form.replaceFieldValue(
77
+ this.getFormFieldName(field),
78
+ index,
79
+ // since unknown doesn't extend an array, it types `value` as never.
80
+ value,
81
+ opts2
82
+ );
83
+ };
84
+ this.removeFieldValue = async (field, index, opts2) => {
85
+ return this.form.removeFieldValue(this.getFormFieldName(field), index, opts2);
86
+ };
87
+ this.swapFieldValues = (field, index1, index2, opts2) => {
88
+ return this.form.swapFieldValues(
89
+ this.getFormFieldName(field),
90
+ index1,
91
+ index2,
92
+ opts2
93
+ );
94
+ };
95
+ this.moveFieldValues = (field, index1, index2, opts2) => {
96
+ return this.form.moveFieldValues(
97
+ this.getFormFieldName(field),
98
+ index1,
99
+ index2,
100
+ opts2
101
+ );
102
+ };
103
+ this.clearFieldValues = (field, opts2) => {
104
+ return this.form.clearFieldValues(this.getFormFieldName(field), opts2);
105
+ };
106
+ this.resetField = (field) => {
107
+ return this.form.resetField(this.getFormFieldName(field));
108
+ };
109
+ this.validateAllFields = (cause) => this.form.validateAllFields(cause);
110
+ if (opts.form instanceof FieldGroupApi) {
111
+ const group = opts.form;
112
+ this.form = group.form;
113
+ if (typeof opts.fields === "string") {
114
+ this.fieldsMap = group.getFormFieldName(opts.fields);
115
+ } else {
116
+ const fields = {
117
+ ...opts.fields
118
+ };
119
+ for (const key in fields) {
120
+ fields[key] = group.getFormFieldName(fields[key]);
121
+ }
122
+ this.fieldsMap = fields;
123
+ }
124
+ } else {
125
+ this.form = opts.form;
126
+ this.fieldsMap = opts.fields;
127
+ }
128
+ this.store = new store.Derived({
129
+ deps: [this.form.store],
130
+ fn: ({ currDepVals }) => {
131
+ const currFormStore = currDepVals[0];
132
+ let values;
133
+ if (typeof this.fieldsMap === "string") {
134
+ values = utils.getBy(currFormStore.values, this.fieldsMap);
135
+ } else {
136
+ values = {};
137
+ const fields = this.fieldsMap;
138
+ for (const key in fields) {
139
+ values[key] = utils.getBy(currFormStore.values, fields[key]);
140
+ }
141
+ }
142
+ return {
143
+ values
144
+ };
145
+ }
146
+ });
147
+ }
148
+ get state() {
149
+ return this.store.state;
150
+ }
151
+ async handleSubmit(submitMeta) {
152
+ return this.form.handleSubmit(submitMeta);
153
+ }
154
+ }
155
+ exports.FieldGroupApi = FieldGroupApi;
156
+ //# sourceMappingURL=FieldGroupApi.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FieldGroupApi.cjs","sources":["../../src/FieldGroupApi.ts"],"sourcesContent":["import { Derived } from '@tanstack/store'\nimport { concatenatePaths, getBy, makePathArray } from './utils'\nimport type { Updater } from './utils'\nimport type {\n FormApi,\n FormAsyncValidateOrFn,\n FormValidateOrFn,\n} from './FormApi'\nimport type { AnyFieldMeta, AnyFieldMetaBase } from './FieldApi'\nimport type {\n DeepKeys,\n DeepKeysOfType,\n DeepValue,\n FieldsMap,\n} from './util-types'\nimport type {\n FieldManipulator,\n UpdateMetaOptions,\n ValidationCause,\n} from './types'\n\nexport type AnyFieldGroupApi = FieldGroupApi<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>\n\nexport interface FieldGroupState<in out TFieldGroupData> {\n /**\n * The current values of the field group\n */\n values: TFieldGroupData\n}\n\n/**\n * An object representing the options for a field group.\n */\nexport interface FieldGroupOptions<\n in out TFormData,\n in out TFieldGroupData,\n in out TFields extends\n | DeepKeysOfType<TFormData, TFieldGroupData | null | undefined>\n | FieldsMap<TFormData, TFieldGroupData>,\n in out TOnMount extends undefined | FormValidateOrFn<TFormData>,\n in out TOnChange extends undefined | FormValidateOrFn<TFormData>,\n in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,\n in out TOnBlur extends undefined | FormValidateOrFn<TFormData>,\n in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,\n in out TOnSubmit extends undefined | FormValidateOrFn<TFormData>,\n in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,\n in out TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,\n in out TSubmitMeta = never,\n> {\n form:\n | FormApi<\n TFormData,\n TOnMount,\n TOnChange,\n TOnChangeAsync,\n TOnBlur,\n TOnBlurAsync,\n TOnSubmit,\n TOnSubmitAsync,\n TOnServer,\n TSubmitMeta\n >\n | FieldGroupApi<\n any,\n TFormData,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n TSubmitMeta\n >\n /**\n * The path to the field group data.\n */\n fields: TFields\n /**\n * The expected subsetValues that the form must provide.\n */\n defaultValues?: TFieldGroupData\n /**\n * onSubmitMeta, the data passed from the handleSubmit handler, to the onSubmit function props\n */\n onSubmitMeta?: TSubmitMeta\n}\n\nexport class FieldGroupApi<\n in out TFormData,\n in out TFieldGroupData,\n in out TFields extends\n | DeepKeysOfType<TFormData, TFieldGroupData | null | undefined>\n | FieldsMap<TFormData, TFieldGroupData>,\n in out TOnMount extends undefined | FormValidateOrFn<TFormData>,\n in out TOnChange extends undefined | FormValidateOrFn<TFormData>,\n in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,\n in out TOnBlur extends undefined | FormValidateOrFn<TFormData>,\n in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,\n in out TOnSubmit extends undefined | FormValidateOrFn<TFormData>,\n in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,\n in out TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,\n in out TSubmitMeta = never,\n> implements FieldManipulator<TFieldGroupData, TSubmitMeta>\n{\n /**\n * The form that called this field group.\n */\n readonly form: FormApi<\n TFormData,\n TOnMount,\n TOnChange,\n TOnChangeAsync,\n TOnBlur,\n TOnBlurAsync,\n TOnSubmit,\n TOnSubmitAsync,\n TOnServer,\n TSubmitMeta\n >\n\n readonly fieldsMap: TFields\n\n /**\n * Get the true name of the field. Not required within `Field` or `AppField`.\n * @private\n */\n getFormFieldName = <TField extends DeepKeys<TFieldGroupData>>(\n subfield: TField,\n ): DeepKeys<TFormData> => {\n if (typeof this.fieldsMap === 'string') {\n return concatenatePaths(this.fieldsMap, subfield)\n }\n\n const firstAccessor = makePathArray(subfield)[0]\n if (typeof firstAccessor !== 'string') {\n // top-level arrays cannot be mapped\n return ''\n }\n\n const restOfPath = subfield.slice(firstAccessor.length)\n const formMappedPath =\n // TFields is either a string or this. See guard above.\n (this.fieldsMap as FieldsMap<TFormData, TFieldGroupData>)[\n firstAccessor as keyof TFieldGroupData\n ]\n\n return concatenatePaths(formMappedPath, restOfPath)\n }\n\n store: Derived<FieldGroupState<TFieldGroupData>>\n\n get state() {\n return this.store.state\n }\n\n /**\n * Constructs a new `FieldGroupApi` instance with the given form options.\n */\n constructor(\n opts: FieldGroupOptions<\n TFormData,\n TFieldGroupData,\n TFields,\n TOnMount,\n TOnChange,\n TOnChangeAsync,\n TOnBlur,\n TOnBlurAsync,\n TOnSubmit,\n TOnSubmitAsync,\n TOnServer,\n TSubmitMeta\n >,\n ) {\n if (opts.form instanceof FieldGroupApi) {\n const group = opts.form\n this.form = group.form as never\n\n // the DeepKey is already namespaced, so we need to ensure that we reference\n // the form and not the group\n if (typeof opts.fields === 'string') {\n this.fieldsMap = group.getFormFieldName(opts.fields) as TFields\n } else {\n // TypeScript has a tough time with generics being a union for some reason\n const fields = {\n ...(opts.fields as FieldsMap<TFormData, TFieldGroupData>),\n }\n for (const key in fields) {\n fields[key] = group.getFormFieldName(fields[key]) as never\n }\n this.fieldsMap = fields as never\n }\n } else {\n this.form = opts.form\n this.fieldsMap = opts.fields\n }\n\n this.store = new Derived({\n deps: [this.form.store],\n fn: ({ currDepVals }) => {\n const currFormStore = currDepVals[0]\n let values: TFieldGroupData\n if (typeof this.fieldsMap === 'string') {\n // all values live at that name, so we can directly fetch it\n values = getBy(currFormStore.values, this.fieldsMap)\n } else {\n // we need to fetch the values from all places where they were mapped from\n values = {} as never\n const fields: Record<keyof TFieldGroupData, string> = this\n .fieldsMap as never\n for (const key in fields) {\n values[key] = getBy(currFormStore.values, fields[key])\n }\n }\n\n return {\n values,\n }\n },\n })\n }\n\n /**\n * Mounts the field group instance to listen to value changes.\n */\n mount = () => {\n const cleanup = this.store.mount()\n\n return cleanup\n }\n\n /**\n * 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.\n */\n validateArrayFieldsStartingFrom = async <\n TField extends DeepKeysOfType<TFieldGroupData, any[]>,\n >(\n field: TField,\n index: number,\n cause: ValidationCause,\n ) => {\n return this.form.validateArrayFieldsStartingFrom(\n this.getFormFieldName(field),\n index,\n cause,\n )\n }\n\n /**\n * Validates a specified field in the form using the correct handlers for a given validation type.\n */\n validateField = <TField extends DeepKeys<TFieldGroupData>>(\n field: TField,\n cause: ValidationCause,\n ) => {\n return this.form.validateField(this.getFormFieldName(field), cause)\n }\n\n /**\n * Handles the form submission, performs validation, and calls the appropriate onSubmit or onSubmitInvalid callbacks.\n */\n handleSubmit(): Promise<void>\n handleSubmit(submitMeta: TSubmitMeta): Promise<void>\n async handleSubmit(submitMeta?: TSubmitMeta): Promise<void> {\n // cast is required since the implementation isn't one of the two overloads\n return this.form.handleSubmit(submitMeta as any)\n }\n\n /**\n * Gets the value of the specified field.\n */\n getFieldValue = <TField extends DeepKeys<TFieldGroupData>>(\n field: TField,\n ): DeepValue<TFieldGroupData, TField> => {\n return this.form.getFieldValue(this.getFormFieldName(field)) as DeepValue<\n TFieldGroupData,\n TField\n >\n }\n\n /**\n * Gets the metadata of the specified field.\n */\n getFieldMeta = <TField extends DeepKeys<TFieldGroupData>>(field: TField) => {\n return this.form.getFieldMeta(this.getFormFieldName(field))\n }\n\n /**\n * Updates the metadata of the specified field.\n */\n setFieldMeta = <TField extends DeepKeys<TFieldGroupData>>(\n field: TField,\n updater: Updater<AnyFieldMetaBase>,\n ) => {\n return this.form.setFieldMeta(this.getFormFieldName(field), updater)\n }\n\n /**\n * Sets the value of the specified field and optionally updates the touched state.\n */\n setFieldValue = <TField extends DeepKeys<TFieldGroupData>>(\n field: TField,\n updater: Updater<DeepValue<TFieldGroupData, TField>>,\n opts?: UpdateMetaOptions,\n ) => {\n return this.form.setFieldValue(\n this.getFormFieldName(field) as never,\n updater as never,\n opts,\n )\n }\n\n /**\n * Delete a field and its subfields.\n */\n deleteField = <TField extends DeepKeys<TFieldGroupData>>(field: TField) => {\n return this.form.deleteField(this.getFormFieldName(field))\n }\n\n /**\n * Pushes a value into an array field.\n */\n pushFieldValue = <TField extends DeepKeysOfType<TFieldGroupData, any[]>>(\n field: TField,\n value: DeepValue<TFieldGroupData, TField> extends any[]\n ? DeepValue<TFieldGroupData, TField>[number]\n : never,\n opts?: UpdateMetaOptions,\n ) => {\n return this.form.pushFieldValue(\n this.getFormFieldName(field),\n // since unknown doesn't extend an array, it types `value` as never.\n value as never,\n opts,\n )\n }\n\n /**\n * Insert a value into an array field at the specified index.\n */\n insertFieldValue = async <\n TField extends DeepKeysOfType<TFieldGroupData, any[]>,\n >(\n field: TField,\n index: number,\n value: DeepValue<TFieldGroupData, TField> extends any[]\n ? DeepValue<TFieldGroupData, TField>[number]\n : never,\n opts?: UpdateMetaOptions,\n ) => {\n return this.form.insertFieldValue(\n this.getFormFieldName(field),\n index,\n // since unknown doesn't extend an array, it types `value` as never.\n value as never,\n opts,\n )\n }\n\n /**\n * Replaces a value into an array field at the specified index.\n */\n replaceFieldValue = async <\n TField extends DeepKeysOfType<TFieldGroupData, any[]>,\n >(\n field: TField,\n index: number,\n value: DeepValue<TFieldGroupData, TField> extends any[]\n ? DeepValue<TFieldGroupData, TField>[number]\n : never,\n opts?: UpdateMetaOptions,\n ) => {\n return this.form.replaceFieldValue(\n this.getFormFieldName(field),\n index,\n // since unknown doesn't extend an array, it types `value` as never.\n value as never,\n opts,\n )\n }\n\n /**\n * Removes a value from an array field at the specified index.\n */\n removeFieldValue = async <\n TField extends DeepKeysOfType<TFieldGroupData, any[]>,\n >(\n field: TField,\n index: number,\n opts?: UpdateMetaOptions,\n ) => {\n return this.form.removeFieldValue(this.getFormFieldName(field), index, opts)\n }\n\n /**\n * Swaps the values at the specified indices within an array field.\n */\n swapFieldValues = <TField extends DeepKeysOfType<TFieldGroupData, any[]>>(\n field: TField,\n index1: number,\n index2: number,\n opts?: UpdateMetaOptions,\n ) => {\n return this.form.swapFieldValues(\n this.getFormFieldName(field),\n index1,\n index2,\n opts,\n )\n }\n\n /**\n * Moves the value at the first specified index to the second specified index within an array field.\n */\n moveFieldValues = <TField extends DeepKeysOfType<TFieldGroupData, any[]>>(\n field: TField,\n index1: number,\n index2: number,\n opts?: UpdateMetaOptions,\n ) => {\n return this.form.moveFieldValues(\n this.getFormFieldName(field),\n index1,\n index2,\n opts,\n )\n }\n\n clearFieldValues = <TField extends DeepKeysOfType<TFieldGroupData, any[]>>(\n field: TField,\n opts?: UpdateMetaOptions,\n ) => {\n return this.form.clearFieldValues(this.getFormFieldName(field), opts)\n }\n\n /**\n * Resets the field value and meta to default state\n */\n resetField = <TField extends DeepKeys<TFieldGroupData>>(field: TField) => {\n return this.form.resetField(this.getFormFieldName(field))\n }\n\n validateAllFields = (cause: ValidationCause) =>\n this.form.validateAllFields(cause)\n}\n"],"names":["concatenatePaths","makePathArray","opts","Derived","getBy"],"mappings":";;;;AAuGO,MAAM,cAgBb;AAAA;AAAA;AAAA;AAAA,EAuDE,YACE,MAcA;AA/CF,SAAA,mBAAmB,CACjB,aACwB;AACpB,UAAA,OAAO,KAAK,cAAc,UAAU;AAC/B,eAAAA,uBAAiB,KAAK,WAAW,QAAQ;AAAA,M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AO,KAAK,WAAW,UAAU;AACnC,aAAK,YAAY,MAAM,iBAAiB,KAAK,MAAM;AAAA,MAAA,OAC9C;AAEL,cAAM,SAAS;AAAA,UACb,GAAI,KAAK;AAAA,QACX;AACA,mBAAW,OAAO,QAAQ;AACxB,iBAAO,GAAG,IAAI,MAAM,iBAAiB,OAAO,GAAG,CAAC;AAAA,QAAA;AAElD,aAAK,YAAY;AAAA,MAAA;AAAA,IACnB,OACK;AACL,WAAK,OAAO,KAAK;AACjB,WAAK,YAAY,KAAK;AAAA,IAAA;AAGnB,SAAA,QAAQ,IAAIC,cAAQ;AAAA,MACvB,MAAM,CAAC,KAAK,KAAK,KAAK;AAAA,MACtB,IAAI,CAAC,EAAE,kBAAkB;AACjB,cAAA,gBAAgB,YAAY,CAAC;AAC/B,YAAA;AACA,YAAA,OAAO,KAAK,cAAc,UAAU;AAEtC,mBAASC,MAAAA,MAAM,cAAc,QAAQ,KAAK,SAAS;AAAA,QAAA,OAC9C;AAEL,mBAAS,CAAC;AACV,gBAAM,SAAgD,KACnD;AACH,qBAAW,OAAO,QAAQ;AACxB,mBAAO,GAAG,IAAIA,MAAA,MAAM,cAAc,QAAQ,OAAO,GAAG,CAAC;AAAA,UAAA;AAAA,QACvD;AAGK,eAAA;AAAA,UACL;AAAA,QACF;AAAA,MAAA;AAAA,IACF,CACD;AAAA,EAAA;AAAA,EApEH,IAAI,QAAQ;AACV,WAAO,KAAK,MAAM;AAAA,EAAA;AAAA,EA+GpB,MAAM,aAAa,YAAyC;AAEnD,WAAA,KAAK,KAAK,aAAa,UAAiB;AAAA,EAAA;AAmLnD;;"}
@@ -0,0 +1,116 @@
1
+ import { Derived } from '@tanstack/store';
2
+ import { Updater } from './utils.cjs';
3
+ import { FormApi, FormAsyncValidateOrFn, FormValidateOrFn } from './FormApi.cjs';
4
+ import { AnyFieldMeta, AnyFieldMetaBase } from './FieldApi.cjs';
5
+ import { DeepKeys, DeepKeysOfType, DeepValue, FieldsMap } from './util-types.cjs';
6
+ import { FieldManipulator, UpdateMetaOptions, ValidationCause } from './types.cjs';
7
+ export type AnyFieldGroupApi = FieldGroupApi<any, any, any, any, any, any, any, any, any, any, any, any>;
8
+ export interface FieldGroupState<in out TFieldGroupData> {
9
+ /**
10
+ * The current values of the field group
11
+ */
12
+ values: TFieldGroupData;
13
+ }
14
+ /**
15
+ * An object representing the options for a field group.
16
+ */
17
+ export interface FieldGroupOptions<in out TFormData, in out TFieldGroupData, in out TFields extends DeepKeysOfType<TFormData, TFieldGroupData | null | undefined> | FieldsMap<TFormData, TFieldGroupData>, in out TOnMount extends undefined | FormValidateOrFn<TFormData>, in out TOnChange extends undefined | FormValidateOrFn<TFormData>, in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>, in out TOnBlur extends undefined | FormValidateOrFn<TFormData>, in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>, in out TOnSubmit extends undefined | FormValidateOrFn<TFormData>, in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>, in out TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>, in out TSubmitMeta = never> {
18
+ form: FormApi<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnServer, TSubmitMeta> | FieldGroupApi<any, TFormData, any, any, any, any, any, any, any, any, any, TSubmitMeta>;
19
+ /**
20
+ * The path to the field group data.
21
+ */
22
+ fields: TFields;
23
+ /**
24
+ * The expected subsetValues that the form must provide.
25
+ */
26
+ defaultValues?: TFieldGroupData;
27
+ /**
28
+ * onSubmitMeta, the data passed from the handleSubmit handler, to the onSubmit function props
29
+ */
30
+ onSubmitMeta?: TSubmitMeta;
31
+ }
32
+ export declare class FieldGroupApi<in out TFormData, in out TFieldGroupData, in out TFields extends DeepKeysOfType<TFormData, TFieldGroupData | null | undefined> | FieldsMap<TFormData, TFieldGroupData>, in out TOnMount extends undefined | FormValidateOrFn<TFormData>, in out TOnChange extends undefined | FormValidateOrFn<TFormData>, in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>, in out TOnBlur extends undefined | FormValidateOrFn<TFormData>, in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>, in out TOnSubmit extends undefined | FormValidateOrFn<TFormData>, in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>, in out TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>, in out TSubmitMeta = never> implements FieldManipulator<TFieldGroupData, TSubmitMeta> {
33
+ /**
34
+ * The form that called this field group.
35
+ */
36
+ readonly form: FormApi<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnServer, TSubmitMeta>;
37
+ readonly fieldsMap: TFields;
38
+ /**
39
+ * Get the true name of the field. Not required within `Field` or `AppField`.
40
+ * @private
41
+ */
42
+ getFormFieldName: <TField extends DeepKeys<TFieldGroupData>>(subfield: TField) => DeepKeys<TFormData>;
43
+ store: Derived<FieldGroupState<TFieldGroupData>>;
44
+ get state(): FieldGroupState<TFieldGroupData>;
45
+ /**
46
+ * Constructs a new `FieldGroupApi` instance with the given form options.
47
+ */
48
+ constructor(opts: FieldGroupOptions<TFormData, TFieldGroupData, TFields, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnServer, TSubmitMeta>);
49
+ /**
50
+ * Mounts the field group instance to listen to value changes.
51
+ */
52
+ mount: () => () => void;
53
+ /**
54
+ * 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.
55
+ */
56
+ validateArrayFieldsStartingFrom: <TField extends DeepKeysOfType<TFieldGroupData, any[]>>(field: TField, index: number, cause: ValidationCause) => Promise<unknown[]>;
57
+ /**
58
+ * Validates a specified field in the form using the correct handlers for a given validation type.
59
+ */
60
+ validateField: <TField extends DeepKeys<TFieldGroupData>>(field: TField, cause: ValidationCause) => unknown[] | Promise<unknown[]>;
61
+ /**
62
+ * Handles the form submission, performs validation, and calls the appropriate onSubmit or onSubmitInvalid callbacks.
63
+ */
64
+ handleSubmit(): Promise<void>;
65
+ handleSubmit(submitMeta: TSubmitMeta): Promise<void>;
66
+ /**
67
+ * Gets the value of the specified field.
68
+ */
69
+ getFieldValue: <TField extends DeepKeys<TFieldGroupData>>(field: TField) => DeepValue<TFieldGroupData, TField>;
70
+ /**
71
+ * Gets the metadata of the specified field.
72
+ */
73
+ getFieldMeta: <TField extends DeepKeys<TFieldGroupData>>(field: TField) => AnyFieldMeta | undefined;
74
+ /**
75
+ * Updates the metadata of the specified field.
76
+ */
77
+ setFieldMeta: <TField extends DeepKeys<TFieldGroupData>>(field: TField, updater: Updater<AnyFieldMetaBase>) => void;
78
+ /**
79
+ * Sets the value of the specified field and optionally updates the touched state.
80
+ */
81
+ setFieldValue: <TField extends DeepKeys<TFieldGroupData>>(field: TField, updater: Updater<DeepValue<TFieldGroupData, TField>>, opts?: UpdateMetaOptions) => void;
82
+ /**
83
+ * Delete a field and its subfields.
84
+ */
85
+ deleteField: <TField extends DeepKeys<TFieldGroupData>>(field: TField) => void;
86
+ /**
87
+ * Pushes a value into an array field.
88
+ */
89
+ pushFieldValue: <TField extends DeepKeysOfType<TFieldGroupData, any[]>>(field: TField, value: DeepValue<TFieldGroupData, TField> extends any[] ? DeepValue<TFieldGroupData, TField>[number] : never, opts?: UpdateMetaOptions) => void;
90
+ /**
91
+ * Insert a value into an array field at the specified index.
92
+ */
93
+ insertFieldValue: <TField extends DeepKeysOfType<TFieldGroupData, any[]>>(field: TField, index: number, value: DeepValue<TFieldGroupData, TField> extends any[] ? DeepValue<TFieldGroupData, TField>[number] : never, opts?: UpdateMetaOptions) => Promise<void>;
94
+ /**
95
+ * Replaces a value into an array field at the specified index.
96
+ */
97
+ replaceFieldValue: <TField extends DeepKeysOfType<TFieldGroupData, any[]>>(field: TField, index: number, value: DeepValue<TFieldGroupData, TField> extends any[] ? DeepValue<TFieldGroupData, TField>[number] : never, opts?: UpdateMetaOptions) => Promise<void>;
98
+ /**
99
+ * Removes a value from an array field at the specified index.
100
+ */
101
+ removeFieldValue: <TField extends DeepKeysOfType<TFieldGroupData, any[]>>(field: TField, index: number, opts?: UpdateMetaOptions) => Promise<void>;
102
+ /**
103
+ * Swaps the values at the specified indices within an array field.
104
+ */
105
+ swapFieldValues: <TField extends DeepKeysOfType<TFieldGroupData, any[]>>(field: TField, index1: number, index2: number, opts?: UpdateMetaOptions) => void;
106
+ /**
107
+ * Moves the value at the first specified index to the second specified index within an array field.
108
+ */
109
+ moveFieldValues: <TField extends DeepKeysOfType<TFieldGroupData, any[]>>(field: TField, index1: number, index2: number, opts?: UpdateMetaOptions) => void;
110
+ clearFieldValues: <TField extends DeepKeysOfType<TFieldGroupData, any[]>>(field: TField, opts?: UpdateMetaOptions) => void;
111
+ /**
112
+ * Resets the field value and meta to default state
113
+ */
114
+ resetField: <TField extends DeepKeys<TFieldGroupData>>(field: TField) => void;
115
+ validateAllFields: (cause: ValidationCause) => Promise<unknown[]>;
116
+ }