@tanstack/form-core 0.41.3 → 0.41.4
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 +3 -3
- package/dist/cjs/FieldApi.cjs.map +1 -1
- package/dist/cjs/FieldApi.d.cts +3 -1
- package/dist/cjs/FormApi.cjs +15 -4
- package/dist/cjs/FormApi.cjs.map +1 -1
- package/dist/cjs/FormApi.d.cts +1 -1
- package/dist/esm/FieldApi.d.ts +3 -1
- package/dist/esm/FieldApi.js +3 -3
- package/dist/esm/FieldApi.js.map +1 -1
- package/dist/esm/FormApi.d.ts +1 -1
- package/dist/esm/FormApi.js +15 -4
- package/dist/esm/FormApi.js.map +1 -1
- package/package.json +1 -1
- package/src/FieldApi.ts +7 -2
- package/src/FormApi.ts +15 -3
package/src/FieldApi.ts
CHANGED
|
@@ -989,12 +989,15 @@ export class FieldApi<
|
|
|
989
989
|
*/
|
|
990
990
|
validate = (
|
|
991
991
|
cause: ValidationCause,
|
|
992
|
+
opts?: { skipFormValidation?: boolean },
|
|
992
993
|
): ValidationError[] | Promise<ValidationError[]> => {
|
|
993
994
|
// If the field is pristine, do not validate
|
|
994
995
|
if (!this.state.meta.isTouched) return []
|
|
995
996
|
|
|
996
997
|
// Attempt to sync validate first
|
|
997
|
-
const { fieldsErrorMap } =
|
|
998
|
+
const { fieldsErrorMap } = opts?.skipFormValidation
|
|
999
|
+
? { fieldsErrorMap: {} as never }
|
|
1000
|
+
: this.form.validateSync(cause)
|
|
998
1001
|
const { hasErrored } = this.validateSync(
|
|
999
1002
|
cause,
|
|
1000
1003
|
fieldsErrorMap[this.name] ?? {},
|
|
@@ -1008,7 +1011,9 @@ export class FieldApi<
|
|
|
1008
1011
|
}
|
|
1009
1012
|
|
|
1010
1013
|
// No error? Attempt async validation
|
|
1011
|
-
const formValidationResultPromise =
|
|
1014
|
+
const formValidationResultPromise = opts?.skipFormValidation
|
|
1015
|
+
? Promise.resolve({})
|
|
1016
|
+
: this.form.validateAsync(cause)
|
|
1012
1017
|
return this.validateAsync(cause, formValidationResultPromise)
|
|
1013
1018
|
}
|
|
1014
1019
|
|
package/src/FormApi.ts
CHANGED
|
@@ -722,7 +722,7 @@ export class FormApi<
|
|
|
722
722
|
}
|
|
723
723
|
|
|
724
724
|
/**
|
|
725
|
-
* Validates
|
|
725
|
+
* Validates all fields using the correct handlers for a given validation cause.
|
|
726
726
|
*/
|
|
727
727
|
validateAllFields = async (cause: ValidationCause) => {
|
|
728
728
|
const fieldValidationPromises: Promise<ValidationError[]>[] = [] as any
|
|
@@ -735,7 +735,9 @@ export class FormApi<
|
|
|
735
735
|
// Validate the field
|
|
736
736
|
fieldValidationPromises.push(
|
|
737
737
|
// Remember, `validate` is either a sync operation or a promise
|
|
738
|
-
Promise.resolve().then(() =>
|
|
738
|
+
Promise.resolve().then(() =>
|
|
739
|
+
fieldInstance.validate(cause, { skipFormValidation: true }),
|
|
740
|
+
),
|
|
739
741
|
)
|
|
740
742
|
// If any fields are not touched
|
|
741
743
|
if (!field.instance.state.meta.isTouched) {
|
|
@@ -1076,9 +1078,19 @@ export class FormApi<
|
|
|
1076
1078
|
this.baseStore.setState((prev) => ({ ...prev, isSubmitting: false }))
|
|
1077
1079
|
}
|
|
1078
1080
|
|
|
1079
|
-
// Validate form and all fields
|
|
1080
1081
|
await this.validateAllFields('submit')
|
|
1081
1082
|
|
|
1083
|
+
if (!this.state.isFieldsValid) {
|
|
1084
|
+
done()
|
|
1085
|
+
this.options.onSubmitInvalid?.({
|
|
1086
|
+
value: this.state.values,
|
|
1087
|
+
formApi: this,
|
|
1088
|
+
})
|
|
1089
|
+
return
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
await this.validate('submit')
|
|
1093
|
+
|
|
1082
1094
|
// Fields are invalid, do not submit
|
|
1083
1095
|
if (!this.state.isValid) {
|
|
1084
1096
|
done()
|