@tanstack/form-core 1.16.0 → 1.18.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 (59) 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 +82 -69
  7. package/dist/cjs/FormApi.cjs.map +1 -1
  8. package/dist/cjs/FormApi.d.cts +45 -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/types.d.cts +6 -3
  22. package/dist/cjs/utils.cjs +51 -63
  23. package/dist/cjs/utils.cjs.map +1 -1
  24. package/dist/cjs/utils.d.cts +11 -5
  25. package/dist/esm/FieldApi.d.ts +33 -30
  26. package/dist/esm/FieldApi.js +48 -40
  27. package/dist/esm/FieldApi.js.map +1 -1
  28. package/dist/esm/FieldGroupApi.d.ts +6 -6
  29. package/dist/esm/FieldGroupApi.js.map +1 -1
  30. package/dist/esm/FormApi.d.ts +45 -35
  31. package/dist/esm/FormApi.js +82 -69
  32. package/dist/esm/FormApi.js.map +1 -1
  33. package/dist/esm/ValidationLogic.d.ts +47 -0
  34. package/dist/esm/ValidationLogic.js +106 -0
  35. package/dist/esm/ValidationLogic.js.map +1 -0
  36. package/dist/esm/formOptions.d.ts +1 -1
  37. package/dist/esm/formOptions.js.map +1 -1
  38. package/dist/esm/index.d.ts +1 -0
  39. package/dist/esm/index.js +3 -0
  40. package/dist/esm/index.js.map +1 -1
  41. package/dist/esm/mergeForm.d.ts +1 -1
  42. package/dist/esm/mergeForm.js.map +1 -1
  43. package/dist/esm/metaHelper.d.ts +1 -1
  44. package/dist/esm/metaHelper.js.map +1 -1
  45. package/dist/esm/types.d.ts +6 -3
  46. package/dist/esm/utils.d.ts +11 -5
  47. package/dist/esm/utils.js +51 -63
  48. package/dist/esm/utils.js.map +1 -1
  49. package/package.json +16 -3
  50. package/src/FieldApi.ts +185 -14
  51. package/src/FieldGroupApi.ts +14 -0
  52. package/src/FormApi.ts +139 -3
  53. package/src/ValidationLogic.ts +200 -0
  54. package/src/formOptions.ts +1 -1
  55. package/src/index.ts +1 -0
  56. package/src/mergeForm.ts +16 -1
  57. package/src/metaHelper.ts +4 -0
  58. package/src/types.ts +17 -1
  59. package/src/utils.ts +159 -109
@@ -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
- (_b = (_a2 = this.options.listeners) == null ? void 0 : _a2.onMount) == null ? void 0 : _b.call(_a2, { formApi: this });
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 = !!((_b = (_a2 = options.transform) == null ? void 0 : _a2.deps) == null ? void 0 : _b.some(
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 && !(opts2 == null ? void 0 : opts2.keepDefaultValues)) {
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
- var _a2;
86
- return getDefaultFormState({
87
- ...this.options.defaultState,
88
- values: values ?? this.options.defaultValues ?? ((_a2 = this.options.defaultState) == null ? void 0 : _a2.values),
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
- var _a2;
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, this.options);
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 == null ? void 0 : fieldErrors[field];
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
- (currentErrorMapSource == null ? void 0 : currentErrorMapSource[errorMapKey]) === "form"
177
+ currentErrorMapSource?.[errorMapKey] === "form"
180
178
  ),
181
179
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
182
- previousErrorValue: currentErrorMap == null ? void 0 : currentErrorMap[errorMapKey]
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
- (currentErrorMap == null ? void 0 : currentErrorMap[errorMapKey]) !== newErrorValue
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 (((_a2 = this.state.errorMap) == null ? void 0 : _a2[errorMapKey]) !== formError) {
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
- ((_b = this.state.errorMap) == null ? void 0 : _b[submitErrKey]) && cause !== "submit" && !hasErrored
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, this.options);
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 == null ? void 0 : fieldValidatorMeta.lastAbortController.abort();
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 == null ? void 0 : fieldErrorsFromFormValidators[field];
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
- (currentErrorMapSource == null ? void 0 : currentErrorMapSource[errorMapKey]) === "form"
317
+ currentErrorMapSource?.[errorMapKey] === "form"
303
318
  ),
304
319
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
305
- previousErrorValue: currentErrorMap == null ? void 0 : currentErrorMap[errorMapKey]
320
+ previousErrorValue: currentErrorMap?.[errorMapKey]
306
321
  });
307
322
  if (
308
323
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
309
- (currentErrorMap == null ? void 0 : currentErrorMap[errorMapKey]) !== newErrorValue
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 == null ? void 0 : fieldValidationResult.fieldErrors) {
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
- var _a2;
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 = (opts2 == null ? void 0 : opts2.dontUpdateMeta) ?? false;
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 == null ? void 0 : prev.errorMap,
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 == null ? void 0 : opts.defaultState,
596
- values: (opts == null ? void 0 : opts.defaultValues) ?? ((_a = opts == null ? void 0 : opts.defaultState) == null ? void 0 : _a.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 == null ? void 0 : prevDepVals[0];
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 == null ? void 0 : prevBaseStore.fieldMetaBase[fieldName];
613
- const prevFieldInfo = prevVal == null ? void 0 : prevVal[fieldName];
626
+ const prevBaseMeta = prevBaseStore?.fieldMetaBase[fieldName];
627
+ const prevFieldInfo = prevVal?.[fieldName];
614
628
  const curFieldVal = getBy(currBaseStore.values, fieldName);
615
- let fieldErrors = prevFieldInfo == null ? void 0 : prevFieldInfo.errors;
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 = (_a2 = this.getFieldInfo(fieldName)) == null ? void 0 : _a2.instance;
634
+ const fieldInstance = this.getFieldInfo(fieldName)?.instance;
621
635
  if (fieldInstance && !fieldInstance.options.disableErrorFlat) {
622
- fieldErrors = fieldErrors == null ? void 0 : fieldErrors.flat(
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
- (_c = (_b = this.getFieldInfo(fieldName)) == null ? void 0 : _b.instance) == null ? void 0 : _c.options.defaultValue
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 == null ? void 0 : prevDepVals[0];
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 && ((_a2 = currBaseStore.errorMap) == null ? void 0 : _a2.onMount)
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
- ((_b = currBaseStore.errorMap) == null ? void 0 : _b.onMount) || // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
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 = (prevVal == null ? void 0 : prevVal.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 = ((_c = this.options.transform) == null ? void 0 : _c.deps) ?? [];
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
- (_d = this.options.transform) == null ? void 0 : _d.fn(newObj);
748
+ this.options.transform?.fn(newObj);
739
749
  state = newObj.state;
740
750
  this.prevTransformArray = transformArray;
741
751
  }
@@ -748,6 +758,9 @@ class FormApi {
748
758
  get state() {
749
759
  return this.store.state;
750
760
  }
761
+ get formId() {
762
+ return this.options.formId;
763
+ }
751
764
  /**
752
765
  * @private
753
766
  */
@@ -761,7 +774,6 @@ class FormApi {
761
774
  return props.validate(props.value);
762
775
  }
763
776
  async handleSubmit(submitMeta) {
764
- var _a, _b, _c, _d, _e, _f, _g, _h;
765
777
  this.baseStore.setState((old) => ({
766
778
  ...old,
767
779
  // Submission attempts mark the form as not submitted
@@ -790,7 +802,7 @@ class FormApi {
790
802
  await this.validateAllFields("submit");
791
803
  if (!this.state.isFieldsValid) {
792
804
  done();
793
- (_b = (_a = this.options).onSubmitInvalid) == null ? void 0 : _b.call(_a, {
805
+ this.options.onSubmitInvalid?.({
794
806
  value: this.state.values,
795
807
  formApi: this,
796
808
  meta: submitMetaArg
@@ -800,7 +812,7 @@ class FormApi {
800
812
  await this.validate("submit");
801
813
  if (!this.state.isValid) {
802
814
  done();
803
- (_d = (_c = this.options).onSubmitInvalid) == null ? void 0 : _d.call(_c, {
815
+ this.options.onSubmitInvalid?.({
804
816
  value: this.state.values,
805
817
  formApi: this,
806
818
  meta: submitMetaArg
@@ -810,21 +822,20 @@ class FormApi {
810
822
  batch(() => {
811
823
  void Object.values(this.fieldInfo).forEach(
812
824
  (field) => {
813
- var _a2, _b2, _c2;
814
- (_c2 = (_b2 = (_a2 = field.instance) == null ? void 0 : _a2.options.listeners) == null ? void 0 : _b2.onSubmit) == null ? void 0 : _c2.call(_b2, {
825
+ field.instance?.options.listeners?.onSubmit?.({
815
826
  value: field.instance.state.value,
816
827
  fieldApi: field.instance
817
828
  });
818
829
  }
819
830
  );
820
831
  });
821
- (_f = (_e = this.options.listeners) == null ? void 0 : _e.onSubmit) == null ? void 0 : _f.call(_e, { formApi: this, meta: submitMetaArg });
832
+ this.options.listeners?.onSubmit?.({ formApi: this, meta: submitMetaArg });
822
833
  try {
823
- await ((_h = (_g = this.options).onSubmit) == null ? void 0 : _h.call(_g, {
834
+ await this.options.onSubmit?.({
824
835
  value: this.state.values,
825
836
  formApi: this,
826
837
  meta: submitMetaArg
827
- }));
838
+ });
828
839
  batch(() => {
829
840
  this.baseStore.setState((prev) => ({
830
841
  ...prev,
@@ -862,7 +873,7 @@ class FormApi {
862
873
  ...prev,
863
874
  errorMap: {
864
875
  ...prev.errorMap,
865
- [errorMapKey]: fieldErrors == null ? void 0 : fieldErrors[fieldName]
876
+ [errorMapKey]: fieldErrors?.[fieldName]
866
877
  },
867
878
  errorSourceMap: {
868
879
  ...prev.errorSourceMap,
@@ -911,6 +922,8 @@ function getErrorMapKey(cause) {
911
922
  return "onMount";
912
923
  case "server":
913
924
  return "onServer";
925
+ case "dynamic":
926
+ return "onDynamic";
914
927
  case "change":
915
928
  default:
916
929
  return "onChange";