Skip to content

Commit 9c343f2

Browse files
committed
Removed debug messages.
1 parent e8442d4 commit 9c343f2

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

src/lib/client/index.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ import type {
3636
ZodEffects,
3737
ZodArray,
3838
ZodAny,
39-
ZodTypeAny,
40-
SafeParseReturnType
39+
ZodTypeAny
4140
} from 'zod';
4241
import { stringify } from 'devalue';
4342
import type { FormFields } from '../index.js';
@@ -969,7 +968,7 @@ async function validateField<T extends AnyZodObject, M>(
969968
leaf.key
970969
);
971970
if (validator) {
972-
console.log('🚀 ~ file: index.ts:972 ~ no effects:', validator);
971+
//console.log('🚀 ~ file: index.ts:972 ~ no effects:', validator);
973972
const result = await validator.safeParseAsync(value);
974973
if (!result.success) {
975974
const errors = result.error.format();
@@ -980,7 +979,7 @@ async function validateField<T extends AnyZodObject, M>(
980979
}
981980
}
982981

983-
console.log('🚀 ~ file: index.ts:983 ~ Effects found, validating all');
982+
//console.log('🚀 ~ file: index.ts:983 ~ Effects found, validating all');
984983

985984
// Effects are found, validate entire data, unfortunately
986985
const result = await (validators as ZodTypeAny).safeParseAsync(
@@ -1049,6 +1048,16 @@ function formEnhance<T extends AnyZodObject, M>(
10491048
);
10501049
}
10511050

1051+
function validateChange(change: string[]) {
1052+
validateField(
1053+
change,
1054+
options.validators,
1055+
options.defaultValidator,
1056+
data,
1057+
errors
1058+
);
1059+
}
1060+
10521061
// Add blur event, to check tainted
10531062
let lastBlur: string[][] = [];
10541063
function checkBlur() {
@@ -1072,13 +1081,7 @@ function formEnhance<T extends AnyZodObject, M>(
10721081

10731082
for (const change of newChanges) {
10741083
//console.log('🚀 ~ file: index.ts:905 ~ BLUR:', change);
1075-
validateField(
1076-
change,
1077-
options.validators,
1078-
options.defaultValidator,
1079-
data,
1080-
errors
1081-
);
1084+
validateChange(change);
10821085
}
10831086
}
10841087
formEl.addEventListener('focusout', checkBlur);
@@ -1117,13 +1120,7 @@ function formEnhance<T extends AnyZodObject, M>(
11171120

11181121
if (shouldValidate) {
11191122
//console.log('🚀 ~ file: index.ts:920 ~ INPUT with error:', change);
1120-
validateField(
1121-
change,
1122-
options.validators,
1123-
options.defaultValidator,
1124-
data,
1125-
errors
1126-
);
1123+
validateChange(change);
11271124
}
11281125
}
11291126
}

src/routes/tests/rex/+page.server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { fail } from '@sveltejs/kit';
22
import type { Actions, PageServerLoad } from './$types';
3-
import { basicSchema } from './schema';
3+
import { basicSchema, subRefined, refined } from './schema';
44
import { message, superValidate } from '$lib/server';
55

66
export const load = (async () => {
77
// Server API:
8-
const form = await superValidate(basicSchema);
8+
const form = await superValidate(subRefined);
99

1010
// Always return { form } in load and form actions.
1111
return { form };
1212
}) satisfies PageServerLoad;
1313

1414
export const actions: Actions = {
1515
default: async ({ request }) => {
16-
const form = await superValidate(request, basicSchema);
16+
const form = await superValidate(request, subRefined);
1717
console.log('POST', form);
1818

1919
// Convenient validation check:

src/routes/tests/rex/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import type { PageData } from './$types';
33
import { superForm } from '$lib/client';
4-
import { basicSchema, refined } from './schema';
4+
import { basicSchema, subRefined, refined } from './schema';
55
import { page } from '$app/stores';
66
77
export let data: PageData;
@@ -11,7 +11,7 @@
1111
data.form,
1212
{
1313
dataType: 'json',
14-
validators: basicSchema,
14+
validators: subRefined,
1515
validationMethod: ($page.url.searchParams.get('method') ??
1616
undefined) as any
1717
}

src/routes/tests/rex/schema.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
import { z } from 'zod';
22

33
export const basicSchema = z.object({
4+
name: z.string().min(4).default('Hello world!'),
5+
email: z.string().email(),
6+
items: z.optional(
7+
z.array(z.object({ title: z.string(), name: z.string().min(3) }))
8+
),
9+
tags: z
10+
.object({
11+
min: z.number().int().min(5),
12+
max: z.number().int().min(5)
13+
})
14+
.array()
15+
.default([{ min: 5, max: 10 }])
16+
});
17+
18+
export const subRefined = z.object({
419
name: z.string().min(4).default('Hello world!'),
520
email: z.string().email(),
621
items: z.optional(

0 commit comments

Comments
 (0)