@tanstack/form-core
Advanced tools
Comparing version 0.41.3 to 0.41.4
@@ -317,3 +317,5 @@ import { Derived } from '@tanstack/store'; | ||
*/ | ||
validate: (cause: ValidationCause) => ValidationError[] | Promise<ValidationError[]>; | ||
validate: (cause: ValidationCause, opts?: { | ||
skipFormValidation?: boolean; | ||
}) => ValidationError[] | Promise<ValidationError[]>; | ||
/** | ||
@@ -320,0 +322,0 @@ * Handles the change event. |
@@ -271,6 +271,6 @@ import { batch, Derived } from "@tanstack/store"; | ||
}; | ||
this.validate = (cause) => { | ||
this.validate = (cause, opts2) => { | ||
var _a; | ||
if (!this.state.meta.isTouched) return []; | ||
const { fieldsErrorMap } = this.form.validateSync(cause); | ||
const { fieldsErrorMap } = (opts2 == null ? void 0 : opts2.skipFormValidation) ? { fieldsErrorMap: {} } : this.form.validateSync(cause); | ||
const { hasErrored } = this.validateSync( | ||
@@ -284,3 +284,3 @@ cause, | ||
} | ||
const formValidationResultPromise = this.form.validateAsync(cause); | ||
const formValidationResultPromise = (opts2 == null ? void 0 : opts2.skipFormValidation) ? Promise.resolve({}) : this.form.validateAsync(cause); | ||
return this.validateAsync(cause, formValidationResultPromise); | ||
@@ -287,0 +287,0 @@ }; |
@@ -294,3 +294,3 @@ import { Derived, Store } from '@tanstack/store'; | ||
/** | ||
* Validates form and all fields in using the correct handlers for a given validation cause. | ||
* Validates all fields using the correct handlers for a given validation cause. | ||
*/ | ||
@@ -297,0 +297,0 @@ validateAllFields: (cause: ValidationCause) => Promise<ValidationError[]>; |
@@ -96,3 +96,5 @@ import { batch, Store, Derived } from "@tanstack/store"; | ||
// Remember, `validate` is either a sync operation or a promise | ||
Promise.resolve().then(() => fieldInstance.validate(cause)) | ||
Promise.resolve().then( | ||
() => fieldInstance.validate(cause, { skipFormValidation: true }) | ||
) | ||
); | ||
@@ -309,3 +311,3 @@ if (!field.instance.state.meta.isTouched) { | ||
this.handleSubmit = async () => { | ||
var _a2, _b, _c, _d; | ||
var _a2, _b, _c, _d, _e, _f; | ||
this.baseStore.setState((old) => ({ | ||
@@ -324,3 +326,3 @@ ...old, | ||
await this.validateAllFields("submit"); | ||
if (!this.state.isValid) { | ||
if (!this.state.isFieldsValid) { | ||
done(); | ||
@@ -333,2 +335,11 @@ (_b = (_a2 = this.options).onSubmitInvalid) == null ? void 0 : _b.call(_a2, { | ||
} | ||
await this.validate("submit"); | ||
if (!this.state.isValid) { | ||
done(); | ||
(_d = (_c = this.options).onSubmitInvalid) == null ? void 0 : _d.call(_c, { | ||
value: this.state.values, | ||
formApi: this | ||
}); | ||
return; | ||
} | ||
batch(() => { | ||
@@ -344,3 +355,3 @@ void Object.values(this.fieldInfo).forEach((field) => { | ||
try { | ||
await ((_d = (_c = this.options).onSubmit) == null ? void 0 : _d.call(_c, { value: this.state.values, formApi: this })); | ||
await ((_f = (_e = this.options).onSubmit) == null ? void 0 : _f.call(_e, { value: this.state.values, formApi: this })); | ||
batch(() => { | ||
@@ -347,0 +358,0 @@ this.baseStore.setState((prev) => ({ ...prev, isSubmitted: true })); |
{ | ||
"name": "@tanstack/form-core", | ||
"version": "0.41.3", | ||
"version": "0.41.4", | ||
"description": "Powerful, type-safe, framework agnostic forms.", | ||
@@ -5,0 +5,0 @@ "author": "tannerlinsley", |
@@ -992,2 +992,3 @@ import { Derived, batch } from '@tanstack/store' | ||
cause: ValidationCause, | ||
opts?: { skipFormValidation?: boolean }, | ||
): ValidationError[] | Promise<ValidationError[]> => { | ||
@@ -998,3 +999,5 @@ // If the field is pristine, do not validate | ||
// Attempt to sync validate first | ||
const { fieldsErrorMap } = this.form.validateSync(cause) | ||
const { fieldsErrorMap } = opts?.skipFormValidation | ||
? { fieldsErrorMap: {} as never } | ||
: this.form.validateSync(cause) | ||
const { hasErrored } = this.validateSync( | ||
@@ -1013,3 +1016,5 @@ cause, | ||
// No error? Attempt async validation | ||
const formValidationResultPromise = this.form.validateAsync(cause) | ||
const formValidationResultPromise = opts?.skipFormValidation | ||
? Promise.resolve({}) | ||
: this.form.validateAsync(cause) | ||
return this.validateAsync(cause, formValidationResultPromise) | ||
@@ -1016,0 +1021,0 @@ } |
@@ -725,3 +725,3 @@ import { Derived, Store, batch } from '@tanstack/store' | ||
/** | ||
* Validates form and all fields in using the correct handlers for a given validation cause. | ||
* Validates all fields using the correct handlers for a given validation cause. | ||
*/ | ||
@@ -739,3 +739,5 @@ validateAllFields = async (cause: ValidationCause) => { | ||
// Remember, `validate` is either a sync operation or a promise | ||
Promise.resolve().then(() => fieldInstance.validate(cause)), | ||
Promise.resolve().then(() => | ||
fieldInstance.validate(cause, { skipFormValidation: true }), | ||
), | ||
) | ||
@@ -1081,5 +1083,15 @@ // If any fields are not touched | ||
// Validate form and all fields | ||
await this.validateAllFields('submit') | ||
if (!this.state.isFieldsValid) { | ||
done() | ||
this.options.onSubmitInvalid?.({ | ||
value: this.state.values, | ||
formApi: this, | ||
}) | ||
return | ||
} | ||
await this.validate('submit') | ||
// Fields are invalid, do not submit | ||
@@ -1086,0 +1098,0 @@ if (!this.state.isValid) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
537241
7019