@tanstack/form-core 1.16.0 → 1.17.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.
- package/dist/cjs/FieldApi.cjs +48 -40
- package/dist/cjs/FieldApi.cjs.map +1 -1
- package/dist/cjs/FieldApi.d.cts +33 -30
- package/dist/cjs/FieldGroupApi.cjs.map +1 -1
- package/dist/cjs/FieldGroupApi.d.cts +6 -6
- package/dist/cjs/FormApi.cjs +79 -69
- package/dist/cjs/FormApi.cjs.map +1 -1
- package/dist/cjs/FormApi.d.cts +40 -35
- package/dist/cjs/ValidationLogic.cjs +106 -0
- package/dist/cjs/ValidationLogic.cjs.map +1 -0
- package/dist/cjs/ValidationLogic.d.cts +47 -0
- package/dist/cjs/formOptions.cjs.map +1 -1
- package/dist/cjs/formOptions.d.cts +1 -1
- package/dist/cjs/index.cjs +3 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -0
- package/dist/cjs/mergeForm.cjs.map +1 -1
- package/dist/cjs/mergeForm.d.cts +1 -1
- package/dist/cjs/metaHelper.cjs.map +1 -1
- package/dist/cjs/metaHelper.d.cts +1 -1
- package/dist/cjs/standardSchemaValidator.cjs.map +1 -1
- package/dist/cjs/types.d.cts +6 -3
- package/dist/cjs/utils.cjs +51 -63
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +11 -5
- package/dist/esm/FieldApi.d.ts +33 -30
- package/dist/esm/FieldApi.js +48 -40
- package/dist/esm/FieldApi.js.map +1 -1
- package/dist/esm/FieldGroupApi.d.ts +6 -6
- package/dist/esm/FieldGroupApi.js.map +1 -1
- package/dist/esm/FormApi.d.ts +40 -35
- package/dist/esm/FormApi.js +79 -69
- package/dist/esm/FormApi.js.map +1 -1
- package/dist/esm/ValidationLogic.d.ts +47 -0
- package/dist/esm/ValidationLogic.js +106 -0
- package/dist/esm/ValidationLogic.js.map +1 -0
- package/dist/esm/formOptions.d.ts +1 -1
- package/dist/esm/formOptions.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/mergeForm.d.ts +1 -1
- package/dist/esm/mergeForm.js.map +1 -1
- package/dist/esm/metaHelper.d.ts +1 -1
- package/dist/esm/metaHelper.js.map +1 -1
- package/dist/esm/standardSchemaValidator.js.map +1 -1
- package/dist/esm/types.d.ts +6 -3
- package/dist/esm/utils.d.ts +11 -5
- package/dist/esm/utils.js +51 -63
- package/dist/esm/utils.js.map +1 -1
- package/package.json +16 -3
- package/src/FieldApi.ts +185 -14
- package/src/FieldGroupApi.ts +14 -0
- package/src/FormApi.ts +131 -3
- package/src/ValidationLogic.ts +200 -0
- package/src/formOptions.ts +1 -1
- package/src/index.ts +1 -0
- package/src/mergeForm.ts +16 -1
- package/src/metaHelper.ts +4 -0
- package/src/types.ts +17 -1
- package/src/utils.ts +159 -109
package/dist/esm/FormApi.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { batch, Store, Derived } from "@tanstack/store";
|
|
2
2
|
import { evaluate, getSyncValidatorArray, determineFormLevelErrorSourceAndValue, getAsyncValidatorArray, getBy, functionalUpdate, setBy, deleteBy, isNonEmptyArray, isGlobalFormValidationError } from "./utils.js";
|
|
3
|
+
import { defaultValidationLogic } from "./ValidationLogic.js";
|
|
3
4
|
import { standardSchemaValidators, isStandardSchemaValidator } from "./standardSchemaValidator.js";
|
|
4
5
|
import { defaultFieldMeta, metaHelper } from "./metaHelper.js";
|
|
5
6
|
function getDefaultFormState(defaultState) {
|
|
@@ -17,7 +18,8 @@ function getDefaultFormState(defaultState) {
|
|
|
17
18
|
onBlur: void 0,
|
|
18
19
|
onSubmit: void 0,
|
|
19
20
|
onMount: void 0,
|
|
20
|
-
onServer: void 0
|
|
21
|
+
onServer: void 0,
|
|
22
|
+
onDynamic: void 0
|
|
21
23
|
}
|
|
22
24
|
};
|
|
23
25
|
}
|
|
@@ -26,32 +28,29 @@ class FormApi {
|
|
|
26
28
|
* Constructs a new `FormApi` instance with the given form options.
|
|
27
29
|
*/
|
|
28
30
|
constructor(opts) {
|
|
29
|
-
var _a;
|
|
30
31
|
this.options = {};
|
|
31
32
|
this.fieldInfo = {};
|
|
32
33
|
this.prevTransformArray = [];
|
|
33
34
|
this.mount = () => {
|
|
34
|
-
var _a2, _b;
|
|
35
35
|
const cleanupFieldMetaDerived = this.fieldMetaDerived.mount();
|
|
36
36
|
const cleanupStoreDerived = this.store.mount();
|
|
37
37
|
const cleanup = () => {
|
|
38
38
|
cleanupFieldMetaDerived();
|
|
39
39
|
cleanupStoreDerived();
|
|
40
40
|
};
|
|
41
|
-
|
|
41
|
+
this.options.listeners?.onMount?.({ formApi: this });
|
|
42
42
|
const { onMount } = this.options.validators || {};
|
|
43
43
|
if (!onMount) return cleanup;
|
|
44
44
|
this.validateSync("mount");
|
|
45
45
|
return cleanup;
|
|
46
46
|
};
|
|
47
47
|
this.update = (options) => {
|
|
48
|
-
var _a2, _b;
|
|
49
48
|
if (!options) return;
|
|
50
49
|
const oldOptions = this.options;
|
|
51
50
|
this.options = options;
|
|
52
|
-
const shouldUpdateReeval = !!
|
|
51
|
+
const shouldUpdateReeval = !!options.transform?.deps?.some(
|
|
53
52
|
(val, i) => val !== this.prevTransformArray[i]
|
|
54
|
-
)
|
|
53
|
+
);
|
|
55
54
|
const shouldUpdateValues = options.defaultValues && !evaluate(options.defaultValues, oldOptions.defaultValues) && !this.state.isTouched;
|
|
56
55
|
const shouldUpdateState = !evaluate(options.defaultState, oldOptions.defaultState) && !this.state.isTouched;
|
|
57
56
|
if (!shouldUpdateValues && !shouldUpdateState && !shouldUpdateReeval) return;
|
|
@@ -74,21 +73,18 @@ class FormApi {
|
|
|
74
73
|
this.reset = (values, opts2) => {
|
|
75
74
|
const { fieldMeta: currentFieldMeta } = this.state;
|
|
76
75
|
const fieldMetaBase = this.resetFieldMeta(currentFieldMeta);
|
|
77
|
-
if (values && !
|
|
76
|
+
if (values && !opts2?.keepDefaultValues) {
|
|
78
77
|
this.options = {
|
|
79
78
|
...this.options,
|
|
80
79
|
defaultValues: values
|
|
81
80
|
};
|
|
82
81
|
}
|
|
83
82
|
this.baseStore.setState(
|
|
84
|
-
() => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
fieldMetaBase
|
|
90
|
-
});
|
|
91
|
-
}
|
|
83
|
+
() => getDefaultFormState({
|
|
84
|
+
...this.options.defaultState,
|
|
85
|
+
values: values ?? this.options.defaultValues ?? this.options.defaultState?.values,
|
|
86
|
+
fieldMetaBase
|
|
87
|
+
})
|
|
92
88
|
);
|
|
93
89
|
};
|
|
94
90
|
this.validateAllFields = async (cause) => {
|
|
@@ -135,8 +131,7 @@ class FormApi {
|
|
|
135
131
|
return fieldErrorMapMap.flat();
|
|
136
132
|
};
|
|
137
133
|
this.validateField = (field, cause) => {
|
|
138
|
-
|
|
139
|
-
const fieldInstance = (_a2 = this.fieldInfo[field]) == null ? void 0 : _a2.instance;
|
|
134
|
+
const fieldInstance = this.fieldInfo[field]?.instance;
|
|
140
135
|
if (!fieldInstance) return [];
|
|
141
136
|
if (!fieldInstance.state.meta.isTouched) {
|
|
142
137
|
fieldInstance.setMeta((prev) => ({ ...prev, isTouched: true }));
|
|
@@ -144,11 +139,14 @@ class FormApi {
|
|
|
144
139
|
return fieldInstance.validate(cause);
|
|
145
140
|
};
|
|
146
141
|
this.validateSync = (cause) => {
|
|
147
|
-
const validates = getSyncValidatorArray(cause,
|
|
142
|
+
const validates = getSyncValidatorArray(cause, {
|
|
143
|
+
...this.options,
|
|
144
|
+
form: this,
|
|
145
|
+
validationLogic: this.options.validationLogic || defaultValidationLogic
|
|
146
|
+
});
|
|
148
147
|
let hasErrored = false;
|
|
149
148
|
const currentValidationErrorMap = {};
|
|
150
149
|
batch(() => {
|
|
151
|
-
var _a2, _b;
|
|
152
150
|
for (const validateObj of validates) {
|
|
153
151
|
if (!validateObj.validate) continue;
|
|
154
152
|
const rawError = this.runValidator({
|
|
@@ -171,15 +169,15 @@ class FormApi {
|
|
|
171
169
|
errorMap: currentErrorMap,
|
|
172
170
|
errorSourceMap: currentErrorMapSource
|
|
173
171
|
} = fieldMeta;
|
|
174
|
-
const newFormValidatorError = fieldErrors
|
|
172
|
+
const newFormValidatorError = fieldErrors?.[field];
|
|
175
173
|
const { newErrorValue, newSource } = determineFormLevelErrorSourceAndValue({
|
|
176
174
|
newFormValidatorError,
|
|
177
175
|
isPreviousErrorFromFormValidator: (
|
|
178
176
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
179
|
-
|
|
177
|
+
currentErrorMapSource?.[errorMapKey] === "form"
|
|
180
178
|
),
|
|
181
179
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
182
|
-
previousErrorValue: currentErrorMap
|
|
180
|
+
previousErrorValue: currentErrorMap?.[errorMapKey]
|
|
183
181
|
});
|
|
184
182
|
if (newSource === "form") {
|
|
185
183
|
currentValidationErrorMap[field] = {
|
|
@@ -189,7 +187,7 @@ class FormApi {
|
|
|
189
187
|
}
|
|
190
188
|
if (
|
|
191
189
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
192
|
-
|
|
190
|
+
currentErrorMap?.[errorMapKey] !== newErrorValue
|
|
193
191
|
) {
|
|
194
192
|
this.setFieldMeta(field, (prev) => ({
|
|
195
193
|
...prev,
|
|
@@ -204,7 +202,7 @@ class FormApi {
|
|
|
204
202
|
}));
|
|
205
203
|
}
|
|
206
204
|
}
|
|
207
|
-
if (
|
|
205
|
+
if (this.state.errorMap?.[errorMapKey] !== formError) {
|
|
208
206
|
this.baseStore.setState((prev) => ({
|
|
209
207
|
...prev,
|
|
210
208
|
errorMap: {
|
|
@@ -220,7 +218,7 @@ class FormApi {
|
|
|
220
218
|
const submitErrKey = getErrorMapKey("submit");
|
|
221
219
|
if (
|
|
222
220
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
223
|
-
|
|
221
|
+
this.state.errorMap?.[submitErrKey] && cause !== "submit" && !hasErrored
|
|
224
222
|
) {
|
|
225
223
|
this.baseStore.setState((prev) => ({
|
|
226
224
|
...prev,
|
|
@@ -230,11 +228,28 @@ class FormApi {
|
|
|
230
228
|
}
|
|
231
229
|
}));
|
|
232
230
|
}
|
|
231
|
+
const serverErrKey = getErrorMapKey("server");
|
|
232
|
+
if (
|
|
233
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
234
|
+
this.state.errorMap?.[serverErrKey] && cause !== "server" && !hasErrored
|
|
235
|
+
) {
|
|
236
|
+
this.baseStore.setState((prev) => ({
|
|
237
|
+
...prev,
|
|
238
|
+
errorMap: {
|
|
239
|
+
...prev.errorMap,
|
|
240
|
+
[serverErrKey]: void 0
|
|
241
|
+
}
|
|
242
|
+
}));
|
|
243
|
+
}
|
|
233
244
|
});
|
|
234
245
|
return { hasErrored, fieldsErrorMap: currentValidationErrorMap };
|
|
235
246
|
};
|
|
236
247
|
this.validateAsync = async (cause) => {
|
|
237
|
-
const validates = getAsyncValidatorArray(cause,
|
|
248
|
+
const validates = getAsyncValidatorArray(cause, {
|
|
249
|
+
...this.options,
|
|
250
|
+
form: this,
|
|
251
|
+
validationLogic: this.options.validationLogic || defaultValidationLogic
|
|
252
|
+
});
|
|
238
253
|
if (!this.state.isFormValidating) {
|
|
239
254
|
this.baseStore.setState((prev) => ({ ...prev, isFormValidating: true }));
|
|
240
255
|
}
|
|
@@ -244,7 +259,7 @@ class FormApi {
|
|
|
244
259
|
if (!validateObj.validate) continue;
|
|
245
260
|
const key = getErrorMapKey(validateObj.cause);
|
|
246
261
|
const fieldValidatorMeta = this.state.validationMetaMap[key];
|
|
247
|
-
fieldValidatorMeta
|
|
262
|
+
fieldValidatorMeta?.lastAbortController.abort();
|
|
248
263
|
const controller = new AbortController();
|
|
249
264
|
this.state.validationMetaMap[key] = {
|
|
250
265
|
lastAbortController: controller
|
|
@@ -294,19 +309,19 @@ class FormApi {
|
|
|
294
309
|
errorMap: currentErrorMap,
|
|
295
310
|
errorSourceMap: currentErrorMapSource
|
|
296
311
|
} = fieldMeta;
|
|
297
|
-
const newFormValidatorError = fieldErrorsFromFormValidators
|
|
312
|
+
const newFormValidatorError = fieldErrorsFromFormValidators?.[field];
|
|
298
313
|
const { newErrorValue, newSource } = determineFormLevelErrorSourceAndValue({
|
|
299
314
|
newFormValidatorError,
|
|
300
315
|
isPreviousErrorFromFormValidator: (
|
|
301
316
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
302
|
-
|
|
317
|
+
currentErrorMapSource?.[errorMapKey] === "form"
|
|
303
318
|
),
|
|
304
319
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
305
|
-
previousErrorValue: currentErrorMap
|
|
320
|
+
previousErrorValue: currentErrorMap?.[errorMapKey]
|
|
306
321
|
});
|
|
307
322
|
if (
|
|
308
323
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
309
|
-
|
|
324
|
+
currentErrorMap?.[errorMapKey] !== newErrorValue
|
|
310
325
|
) {
|
|
311
326
|
this.setFieldMeta(field, (prev) => ({
|
|
312
327
|
...prev,
|
|
@@ -339,7 +354,7 @@ class FormApi {
|
|
|
339
354
|
if (promises.length) {
|
|
340
355
|
results = await Promise.all(promises);
|
|
341
356
|
for (const fieldValidationResult of results) {
|
|
342
|
-
if (fieldValidationResult
|
|
357
|
+
if (fieldValidationResult?.fieldErrors) {
|
|
343
358
|
const { errorMapKey } = fieldValidationResult;
|
|
344
359
|
for (const [field, fieldError] of Object.entries(
|
|
345
360
|
fieldValidationResult.fieldErrors
|
|
@@ -372,17 +387,17 @@ class FormApi {
|
|
|
372
387
|
return this.state.fieldMeta[field];
|
|
373
388
|
};
|
|
374
389
|
this.getFieldInfo = (field) => {
|
|
375
|
-
|
|
376
|
-
return (_a2 = this.fieldInfo)[field] || (_a2[field] = {
|
|
390
|
+
return this.fieldInfo[field] ||= {
|
|
377
391
|
instance: null,
|
|
378
392
|
validationMetaMap: {
|
|
379
393
|
onChange: void 0,
|
|
380
394
|
onBlur: void 0,
|
|
381
395
|
onSubmit: void 0,
|
|
382
396
|
onMount: void 0,
|
|
383
|
-
onServer: void 0
|
|
397
|
+
onServer: void 0,
|
|
398
|
+
onDynamic: void 0
|
|
384
399
|
}
|
|
385
|
-
}
|
|
400
|
+
};
|
|
386
401
|
};
|
|
387
402
|
this.setFieldMeta = (field, updater) => {
|
|
388
403
|
this.baseStore.setState((prev) => {
|
|
@@ -409,7 +424,7 @@ class FormApi {
|
|
|
409
424
|
);
|
|
410
425
|
};
|
|
411
426
|
this.setFieldValue = (field, updater, opts2) => {
|
|
412
|
-
const dontUpdateMeta =
|
|
427
|
+
const dontUpdateMeta = opts2?.dontUpdateMeta ?? false;
|
|
413
428
|
batch(() => {
|
|
414
429
|
if (!dontUpdateMeta) {
|
|
415
430
|
this.setFieldMeta(field, (prev) => ({
|
|
@@ -418,7 +433,7 @@ class FormApi {
|
|
|
418
433
|
isDirty: true,
|
|
419
434
|
errorMap: {
|
|
420
435
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
421
|
-
...prev
|
|
436
|
+
...prev?.errorMap,
|
|
422
437
|
onMount: void 0
|
|
423
438
|
}
|
|
424
439
|
}));
|
|
@@ -592,16 +607,15 @@ class FormApi {
|
|
|
592
607
|
};
|
|
593
608
|
this.baseStore = new Store(
|
|
594
609
|
getDefaultFormState({
|
|
595
|
-
...opts
|
|
596
|
-
values:
|
|
610
|
+
...opts?.defaultState,
|
|
611
|
+
values: opts?.defaultValues ?? opts?.defaultState?.values
|
|
597
612
|
})
|
|
598
613
|
);
|
|
599
614
|
this.fieldMetaDerived = new Derived({
|
|
600
615
|
deps: [this.baseStore],
|
|
601
616
|
fn: ({ prevDepVals, currDepVals, prevVal: _prevVal }) => {
|
|
602
|
-
var _a2, _b, _c;
|
|
603
617
|
const prevVal = _prevVal;
|
|
604
|
-
const prevBaseStore = prevDepVals
|
|
618
|
+
const prevBaseStore = prevDepVals?.[0];
|
|
605
619
|
const currBaseStore = currDepVals[0];
|
|
606
620
|
let originalMetaCount = 0;
|
|
607
621
|
const fieldMeta = {};
|
|
@@ -609,17 +623,17 @@ class FormApi {
|
|
|
609
623
|
currBaseStore.fieldMetaBase
|
|
610
624
|
)) {
|
|
611
625
|
const currBaseMeta = currBaseStore.fieldMetaBase[fieldName];
|
|
612
|
-
const prevBaseMeta = prevBaseStore
|
|
613
|
-
const prevFieldInfo = prevVal
|
|
626
|
+
const prevBaseMeta = prevBaseStore?.fieldMetaBase[fieldName];
|
|
627
|
+
const prevFieldInfo = prevVal?.[fieldName];
|
|
614
628
|
const curFieldVal = getBy(currBaseStore.values, fieldName);
|
|
615
|
-
let fieldErrors = prevFieldInfo
|
|
629
|
+
let fieldErrors = prevFieldInfo?.errors;
|
|
616
630
|
if (!prevBaseMeta || currBaseMeta.errorMap !== prevBaseMeta.errorMap) {
|
|
617
631
|
fieldErrors = Object.values(currBaseMeta.errorMap ?? {}).filter(
|
|
618
632
|
(val) => val !== void 0
|
|
619
633
|
);
|
|
620
|
-
const fieldInstance =
|
|
634
|
+
const fieldInstance = this.getFieldInfo(fieldName)?.instance;
|
|
621
635
|
if (fieldInstance && !fieldInstance.options.disableErrorFlat) {
|
|
622
|
-
fieldErrors = fieldErrors
|
|
636
|
+
fieldErrors = fieldErrors?.flat(
|
|
623
637
|
1
|
|
624
638
|
);
|
|
625
639
|
}
|
|
@@ -632,7 +646,7 @@ class FormApi {
|
|
|
632
646
|
) || evaluate(
|
|
633
647
|
curFieldVal,
|
|
634
648
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
635
|
-
|
|
649
|
+
this.getFieldInfo(fieldName)?.instance?.options.defaultValue
|
|
636
650
|
);
|
|
637
651
|
if (prevFieldInfo && prevFieldInfo.isPristine === isFieldPristine && prevFieldInfo.isValid === isFieldValid && prevFieldInfo.isDefaultValue === isDefaultValue && prevFieldInfo.errors === fieldErrors && currBaseMeta === prevBaseMeta) {
|
|
638
652
|
fieldMeta[fieldName] = prevFieldInfo;
|
|
@@ -657,9 +671,8 @@ class FormApi {
|
|
|
657
671
|
this.store = new Derived({
|
|
658
672
|
deps: [this.baseStore, this.fieldMetaDerived],
|
|
659
673
|
fn: ({ prevDepVals, currDepVals, prevVal: _prevVal }) => {
|
|
660
|
-
var _a2, _b, _c, _d;
|
|
661
674
|
const prevVal = _prevVal;
|
|
662
|
-
const prevBaseStore = prevDepVals
|
|
675
|
+
const prevBaseStore = prevDepVals?.[0];
|
|
663
676
|
const currBaseStore = currDepVals[0];
|
|
664
677
|
const currFieldMeta = currDepVals[1];
|
|
665
678
|
const fieldMetaValues = Object.values(currFieldMeta).filter(
|
|
@@ -676,20 +689,17 @@ class FormApi {
|
|
|
676
689
|
);
|
|
677
690
|
const shouldInvalidateOnMount = (
|
|
678
691
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
679
|
-
isTouched &&
|
|
692
|
+
isTouched && currBaseStore.errorMap?.onMount
|
|
680
693
|
);
|
|
681
694
|
const isDirty = fieldMetaValues.some((field) => field.isDirty);
|
|
682
695
|
const isPristine = !isDirty;
|
|
683
696
|
const hasOnMountError = Boolean(
|
|
684
697
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
685
|
-
|
|
686
|
-
fieldMetaValues.some((f) =>
|
|
687
|
-
var _a3;
|
|
688
|
-
return (_a3 = f == null ? void 0 : f.errorMap) == null ? void 0 : _a3.onMount;
|
|
689
|
-
})
|
|
698
|
+
currBaseStore.errorMap?.onMount || // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
699
|
+
fieldMetaValues.some((f) => f?.errorMap?.onMount)
|
|
690
700
|
);
|
|
691
701
|
const isValidating = !!isFieldsValidating;
|
|
692
|
-
let errors =
|
|
702
|
+
let errors = prevVal?.errors ?? [];
|
|
693
703
|
if (!prevBaseStore || currBaseStore.errorMap !== prevBaseStore.errorMap) {
|
|
694
704
|
errors = Object.values(currBaseStore.errorMap).reduce((prev, curr) => {
|
|
695
705
|
if (curr === void 0) return prev;
|
|
@@ -731,11 +741,11 @@ class FormApi {
|
|
|
731
741
|
isDefaultValue,
|
|
732
742
|
isDirty
|
|
733
743
|
};
|
|
734
|
-
const transformArray =
|
|
744
|
+
const transformArray = this.options.transform?.deps ?? [];
|
|
735
745
|
const shouldTransform = transformArray.length !== this.prevTransformArray.length || transformArray.some((val, i) => val !== this.prevTransformArray[i]);
|
|
736
746
|
if (shouldTransform) {
|
|
737
747
|
const newObj = Object.assign({}, this, { state });
|
|
738
|
-
|
|
748
|
+
this.options.transform?.fn(newObj);
|
|
739
749
|
state = newObj.state;
|
|
740
750
|
this.prevTransformArray = transformArray;
|
|
741
751
|
}
|
|
@@ -761,7 +771,6 @@ class FormApi {
|
|
|
761
771
|
return props.validate(props.value);
|
|
762
772
|
}
|
|
763
773
|
async handleSubmit(submitMeta) {
|
|
764
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
765
774
|
this.baseStore.setState((old) => ({
|
|
766
775
|
...old,
|
|
767
776
|
// Submission attempts mark the form as not submitted
|
|
@@ -790,7 +799,7 @@ class FormApi {
|
|
|
790
799
|
await this.validateAllFields("submit");
|
|
791
800
|
if (!this.state.isFieldsValid) {
|
|
792
801
|
done();
|
|
793
|
-
|
|
802
|
+
this.options.onSubmitInvalid?.({
|
|
794
803
|
value: this.state.values,
|
|
795
804
|
formApi: this,
|
|
796
805
|
meta: submitMetaArg
|
|
@@ -800,7 +809,7 @@ class FormApi {
|
|
|
800
809
|
await this.validate("submit");
|
|
801
810
|
if (!this.state.isValid) {
|
|
802
811
|
done();
|
|
803
|
-
|
|
812
|
+
this.options.onSubmitInvalid?.({
|
|
804
813
|
value: this.state.values,
|
|
805
814
|
formApi: this,
|
|
806
815
|
meta: submitMetaArg
|
|
@@ -810,21 +819,20 @@ class FormApi {
|
|
|
810
819
|
batch(() => {
|
|
811
820
|
void Object.values(this.fieldInfo).forEach(
|
|
812
821
|
(field) => {
|
|
813
|
-
|
|
814
|
-
(_c2 = (_b2 = (_a2 = field.instance) == null ? void 0 : _a2.options.listeners) == null ? void 0 : _b2.onSubmit) == null ? void 0 : _c2.call(_b2, {
|
|
822
|
+
field.instance?.options.listeners?.onSubmit?.({
|
|
815
823
|
value: field.instance.state.value,
|
|
816
824
|
fieldApi: field.instance
|
|
817
825
|
});
|
|
818
826
|
}
|
|
819
827
|
);
|
|
820
828
|
});
|
|
821
|
-
|
|
829
|
+
this.options.listeners?.onSubmit?.({ formApi: this, meta: submitMetaArg });
|
|
822
830
|
try {
|
|
823
|
-
await
|
|
831
|
+
await this.options.onSubmit?.({
|
|
824
832
|
value: this.state.values,
|
|
825
833
|
formApi: this,
|
|
826
834
|
meta: submitMetaArg
|
|
827
|
-
})
|
|
835
|
+
});
|
|
828
836
|
batch(() => {
|
|
829
837
|
this.baseStore.setState((prev) => ({
|
|
830
838
|
...prev,
|
|
@@ -862,7 +870,7 @@ class FormApi {
|
|
|
862
870
|
...prev,
|
|
863
871
|
errorMap: {
|
|
864
872
|
...prev.errorMap,
|
|
865
|
-
[errorMapKey]: fieldErrors
|
|
873
|
+
[errorMapKey]: fieldErrors?.[fieldName]
|
|
866
874
|
},
|
|
867
875
|
errorSourceMap: {
|
|
868
876
|
...prev.errorSourceMap,
|
|
@@ -911,6 +919,8 @@ function getErrorMapKey(cause) {
|
|
|
911
919
|
return "onMount";
|
|
912
920
|
case "server":
|
|
913
921
|
return "onServer";
|
|
922
|
+
case "dynamic":
|
|
923
|
+
return "onDynamic";
|
|
914
924
|
case "change":
|
|
915
925
|
default:
|
|
916
926
|
return "onChange";
|