@tanstack/form-core 1.7.0 → 1.9.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/src/FormApi.ts CHANGED
@@ -265,6 +265,7 @@ export interface FormListeners<
265
265
  >
266
266
  fieldApi: AnyFieldApi
267
267
  }) => void
268
+ onChangeDebounceMs?: number
268
269
 
269
270
  onBlur?: (props: {
270
271
  formApi: FormApi<
@@ -281,6 +282,7 @@ export interface FormListeners<
281
282
  >
282
283
  fieldApi: AnyFieldApi
283
284
  }) => void
285
+ onBlurDebounceMs?: number
284
286
 
285
287
  onMount?: (props: {
286
288
  formApi: FormApi<
@@ -605,7 +607,7 @@ export type DerivedFormState<
605
607
  */
606
608
  isFieldsValidating: boolean
607
609
  /**
608
- * A boolean indicating if all the form fields are valid.
610
+ * A boolean indicating if all the form fields are valid. Evaluates `true` if there are no field errors.
609
611
  */
610
612
  isFieldsValid: boolean
611
613
  /**
@@ -617,15 +619,15 @@ export type DerivedFormState<
617
619
  */
618
620
  isBlurred: boolean
619
621
  /**
620
- * A boolean indicating if any of the form's fields' values have been modified by the user. `True` if the user have modified at least one of the fields. Opposite of `isPristine`.
622
+ * A boolean indicating if any of the form's fields' values have been modified by the user. Evaluates `true` if the user have modified at least one of the fields. Opposite of `isPristine`.
621
623
  */
622
624
  isDirty: boolean
623
625
  /**
624
- * A boolean indicating if none of the form's fields' values have been modified by the user. `True` if the user have not modified any of the fields. Opposite of `isDirty`.
626
+ * A boolean indicating if none of the form's fields' values have been modified by the user. Evaluates `true` if the user have not modified any of the fields. Opposite of `isDirty`.
625
627
  */
626
628
  isPristine: boolean
627
629
  /**
628
- * A boolean indicating if the form and all its fields are valid.
630
+ * A boolean indicating if the form and all its fields are valid. Evaluates `true` if there are no errors.
629
631
  */
630
632
  isValid: boolean
631
633
  /**
@@ -909,12 +911,14 @@ export class FormApi<
909
911
  }
910
912
  }
911
913
 
912
- // As a primitive, we don't need to aggressively persist the same referential value for performance reasons
914
+ // As primitives, we don't need to aggressively persist the same referential value for performance reasons
913
915
  const isFieldPristine = !currBaseVal.isDirty
916
+ const isFieldValid = !isNonEmptyArray(fieldErrors ?? [])
914
917
 
915
918
  if (
916
919
  prevFieldInfo &&
917
920
  prevFieldInfo.isPristine === isFieldPristine &&
921
+ prevFieldInfo.isValid === isFieldValid &&
918
922
  prevFieldInfo.errors === fieldErrors &&
919
923
  currBaseVal === prevBaseVal
920
924
  ) {
@@ -927,6 +931,7 @@ export class FormApi<
927
931
  ...currBaseVal,
928
932
  errors: fieldErrors,
929
933
  isPristine: isFieldPristine,
934
+ isValid: isFieldValid,
930
935
  } as AnyFieldMeta
931
936
  }
932
937
 
@@ -961,31 +966,27 @@ export class FormApi<
961
966
  | undefined
962
967
  const prevBaseStore = prevDepVals?.[0]
963
968
  const currBaseStore = currDepVals[0]
969
+ const currFieldMeta = currDepVals[1]
964
970
 
965
971
  // Computed state
966
- const fieldMetaValues = Object.values(currBaseStore.fieldMetaBase) as (
967
- | AnyFieldMeta
968
- | undefined
969
- )[]
972
+ const fieldMetaValues = Object.values(currFieldMeta).filter(
973
+ Boolean,
974
+ ) as AnyFieldMeta[]
970
975
 
971
976
  const isFieldsValidating = fieldMetaValues.some(
972
- (field) => field?.isValidating,
977
+ (field) => field.isValidating,
973
978
  )
974
979
 
975
- const isFieldsValid = !fieldMetaValues.some(
976
- (field) =>
977
- field?.errorMap &&
978
- isNonEmptyArray(Object.values(field.errorMap).filter(Boolean)),
979
- )
980
+ const isFieldsValid = fieldMetaValues.every((field) => field.isValid)
980
981
 
981
- const isTouched = fieldMetaValues.some((field) => field?.isTouched)
982
- const isBlurred = fieldMetaValues.some((field) => field?.isBlurred)
982
+ const isTouched = fieldMetaValues.some((field) => field.isTouched)
983
+ const isBlurred = fieldMetaValues.some((field) => field.isBlurred)
983
984
 
984
985
  const shouldInvalidateOnMount =
985
986
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
986
- isTouched && currBaseStore?.errorMap?.onMount
987
+ isTouched && currBaseStore.errorMap?.onMount
987
988
 
988
- const isDirty = fieldMetaValues.some((field) => field?.isDirty)
989
+ const isDirty = fieldMetaValues.some((field) => field.isDirty)
989
990
  const isPristine = !isDirty
990
991
 
991
992
  const hasOnMountError = Boolean(
package/src/metaHelper.ts CHANGED
@@ -14,6 +14,7 @@ export const defaultFieldMeta: AnyFieldMeta = {
14
14
  isBlurred: false,
15
15
  isDirty: false,
16
16
  isPristine: true,
17
+ isValid: true,
17
18
  errors: [],
18
19
  errorMap: {},
19
20
  errorSourceMap: {},