Skip to content

Commit 4b97999

Browse files
committed
Added future test for schema references
1 parent 000b2cd commit 4b97999

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

src/routes/(v2)/v2/Navigation.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
'issue-356',
4141
'issue-358',
4242
'issue-360',
43-
'unknown-in-schema'
43+
'unknown-in-schema',
44+
'issue-374'
4445
].sort();
4546
</script>
4647

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { superValidate, message } from '$lib/index.js';
2+
import { zod } from '$lib/adapters/zod.js';
3+
import { fail } from '@sveltejs/kit';
4+
import { schema } from './schema.js';
5+
6+
export const load = async () => {
7+
const form = await superValidate(zod(schema));
8+
return { form };
9+
};
10+
11+
export const actions = {
12+
default: async ({ request }) => {
13+
const form = await superValidate(request, zod(schema));
14+
console.log(form);
15+
16+
if (!form.valid) return fail(400, { form });
17+
18+
return message(form, 'Form posted successfully!');
19+
}
20+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<script lang="ts">
2+
import { page } from '$app/stores';
3+
import { superForm } from '$lib/index.js';
4+
import SuperDebug from '$lib/index.js';
5+
6+
export let data;
7+
8+
const { form, errors, message, enhance } = superForm(data.form, {
9+
SPA: true,
10+
dataType: 'json'
11+
});
12+
</script>
13+
14+
<SuperDebug data={$form} />
15+
16+
<h3>Reusable Zod schemas</h3>
17+
18+
<form method="POST" use:enhance>
19+
<button>Submit</button>
20+
</form>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { z } from 'zod';
2+
3+
const otherSchema1 = z.string();
4+
const otherSchema2 = z.object({
5+
value: z.string()
6+
});
7+
8+
export const schema = z.object({
9+
obj1: otherSchema1,
10+
obj2: otherSchema1,
11+
12+
obj3: otherSchema2,
13+
obj4: otherSchema2
14+
});

0 commit comments

Comments
 (0)