Skip to content

Commit d605a40

Browse files
committed
Form-level errors can be added with setError, using an empty string as path.
1 parent 4b92fc2 commit d605a40

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
### Fixed
1616

1717
- Form data was reset to its previous state when `error` was thrown.
18+
- Form-level errors can be added with `setError`, using an empty string as path.
1819

1920
## [1.0.0-rc.3]
2021

src/lib/superValidate.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const setMessage = message;
7070
*/
7171
export function setError<T extends ZodValidation<AnyZodObject>>(
7272
form: SuperValidated<T, unknown>,
73-
path: StringPathLeaves<z.infer<UnwrapEffects<T>>>,
73+
path: '' | StringPathLeaves<z.infer<UnwrapEffects<T>>>,
7474
error: string | string[],
7575
options: { overwrite?: boolean; status?: NumericRange<400, 599> } = {
7676
overwrite: false,
@@ -82,10 +82,6 @@ export function setError<T extends ZodValidation<AnyZodObject>>(
8282
if (!form.errors) form.errors = {};
8383

8484
if (path === null || path === '') {
85-
console.warn(
86-
'Warning: Form-level errors added with "setError" will conflict with client-side validation. ' +
87-
'Use refine/superRefine on the schema instead, or the "message" helper.'
88-
);
8985
if (!form.errors._errors) form.errors._errors = [];
9086
form.errors._errors = form.errors._errors.concat(errArr);
9187
} else {

0 commit comments

Comments
 (0)