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