@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/dist/cjs/FieldApi.cjs +48 -19
- package/dist/cjs/FieldApi.cjs.map +1 -1
- package/dist/cjs/FieldApi.d.cts +5 -0
- package/dist/cjs/FormApi.cjs +14 -11
- package/dist/cjs/FormApi.cjs.map +1 -1
- package/dist/cjs/FormApi.d.cts +6 -4
- package/dist/cjs/metaHelper.cjs +1 -0
- package/dist/cjs/metaHelper.cjs.map +1 -1
- package/dist/esm/FieldApi.d.ts +5 -0
- package/dist/esm/FieldApi.js +48 -19
- package/dist/esm/FieldApi.js.map +1 -1
- package/dist/esm/FormApi.d.ts +6 -4
- package/dist/esm/FormApi.js +14 -11
- package/dist/esm/FormApi.js.map +1 -1
- package/dist/esm/metaHelper.js +1 -0
- package/dist/esm/metaHelper.js.map +1 -1
- package/package.json +1 -1
- package/src/FieldApi.ts +47 -14
- package/src/FormApi.ts +20 -19
- package/src/metaHelper.ts +1 -0
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. `
|
|
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. `
|
|
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
|
|
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(
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
)[]
|
|
972
|
+
const fieldMetaValues = Object.values(currFieldMeta).filter(
|
|
973
|
+
Boolean,
|
|
974
|
+
) as AnyFieldMeta[]
|
|
970
975
|
|
|
971
976
|
const isFieldsValidating = fieldMetaValues.some(
|
|
972
|
-
(field) => field
|
|
977
|
+
(field) => field.isValidating,
|
|
973
978
|
)
|
|
974
979
|
|
|
975
|
-
const isFieldsValid =
|
|
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
|
|
982
|
-
const isBlurred = fieldMetaValues.some((field) => field
|
|
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
|
|
987
|
+
isTouched && currBaseStore.errorMap?.onMount
|
|
987
988
|
|
|
988
|
-
const isDirty = fieldMetaValues.some((field) => field
|
|
989
|
+
const isDirty = fieldMetaValues.some((field) => field.isDirty)
|
|
989
990
|
const isPristine = !isDirty
|
|
990
991
|
|
|
991
992
|
const hasOnMountError = Boolean(
|