@tanstack/form-core 0.26.4 → 0.28.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 +14 -2
- package/dist/cjs/FieldApi.cjs.map +1 -1
- package/dist/cjs/FieldApi.d.cts +4 -0
- package/dist/cjs/FormApi.cjs +12 -0
- package/dist/cjs/FormApi.cjs.map +1 -1
- package/dist/cjs/FormApi.d.cts +4 -0
- package/dist/cjs/mergeForm.cjs.map +1 -1
- package/dist/esm/FieldApi.d.ts +4 -0
- package/dist/esm/FieldApi.js +14 -2
- package/dist/esm/FieldApi.js.map +1 -1
- package/dist/esm/FormApi.d.ts +4 -0
- package/dist/esm/FormApi.js +12 -0
- package/dist/esm/FormApi.js.map +1 -1
- package/dist/esm/mergeForm.js.map +1 -1
- package/package.json +2 -2
- package/src/FieldApi.ts +55 -40
- package/src/FormApi.ts +22 -8
- package/src/mergeForm.ts +1 -1
package/src/FormApi.ts
CHANGED
|
@@ -37,9 +37,10 @@ export type FormValidateFn<
|
|
|
37
37
|
export type FormValidateOrFn<
|
|
38
38
|
TFormData,
|
|
39
39
|
TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,
|
|
40
|
-
> =
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
> =
|
|
41
|
+
TFormValidator extends Validator<TFormData, infer TFN>
|
|
42
|
+
? TFN
|
|
43
|
+
: FormValidateFn<TFormData, TFormValidator>
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
46
|
* @private
|
|
@@ -59,9 +60,10 @@ export type FormValidateAsyncFn<
|
|
|
59
60
|
export type FormAsyncValidateOrFn<
|
|
60
61
|
TFormData,
|
|
61
62
|
TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,
|
|
62
|
-
> =
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
> =
|
|
64
|
+
TFormValidator extends Validator<TFormData, infer FFN>
|
|
65
|
+
? FFN | FormValidateAsyncFn<TFormData, TFormValidator>
|
|
66
|
+
: FormValidateAsyncFn<TFormData, TFormValidator>
|
|
65
67
|
|
|
66
68
|
export interface FormValidators<
|
|
67
69
|
TFormData,
|
|
@@ -587,7 +589,7 @@ export class FormApi<
|
|
|
587
589
|
field: TField,
|
|
588
590
|
cause: ValidationCause,
|
|
589
591
|
) => {
|
|
590
|
-
// eslint-disable-next-line
|
|
592
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
591
593
|
const fieldInstance = this.fieldInfo[field]?.instance
|
|
592
594
|
if (!fieldInstance) return []
|
|
593
595
|
|
|
@@ -843,7 +845,7 @@ export class FormApi<
|
|
|
843
845
|
getFieldInfo = <TField extends DeepKeys<TFormData>>(
|
|
844
846
|
field: TField,
|
|
845
847
|
): FieldInfo<TFormData, TFormValidator> => {
|
|
846
|
-
// eslint-disable-next-line
|
|
848
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
847
849
|
return (this.fieldInfo[field] ||= {
|
|
848
850
|
instance: null,
|
|
849
851
|
validationMetaMap: {
|
|
@@ -1093,6 +1095,18 @@ export class FormApi<
|
|
|
1093
1095
|
this.validateField(`${field}[${index1}]` as DeepKeys<TFormData>, 'change')
|
|
1094
1096
|
this.validateField(`${field}[${index2}]` as DeepKeys<TFormData>, 'change')
|
|
1095
1097
|
}
|
|
1098
|
+
/**
|
|
1099
|
+
* Updates the form's errorMap
|
|
1100
|
+
*/
|
|
1101
|
+
setErrorMap(errorMap: ValidationErrorMap) {
|
|
1102
|
+
this.store.setState((prev) => ({
|
|
1103
|
+
...prev,
|
|
1104
|
+
errorMap: {
|
|
1105
|
+
...prev.errorMap,
|
|
1106
|
+
...errorMap,
|
|
1107
|
+
},
|
|
1108
|
+
}))
|
|
1109
|
+
}
|
|
1096
1110
|
}
|
|
1097
1111
|
|
|
1098
1112
|
function normalizeError(rawError?: ValidationError) {
|
package/src/mergeForm.ts
CHANGED
|
@@ -24,7 +24,7 @@ export function mutateMergeDeep(target: object, source: object): object {
|
|
|
24
24
|
mutateMergeDeep(target[targetKey] as {}, source[sourceKey] as {})
|
|
25
25
|
} else {
|
|
26
26
|
// Prevent assigning undefined to target, only if undefined is not explicitly set on source
|
|
27
|
-
// eslint-disable-next-line
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
28
28
|
if (!(sourceKey in source) && source[sourceKey] === undefined) {
|
|
29
29
|
continue
|
|
30
30
|
}
|