Skip to content

Commit 6faf42e

Browse files
committed
Test case for future PR
1 parent 771b74a commit 6faf42e

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import type { Actions, PageServerLoad } from './$types.js';
2+
3+
import { superValidate, message } from '$lib/index.js';
4+
import { zod } from '$lib/adapters/zod.js';
5+
import { fail } from '@sveltejs/kit';
6+
import { schema } from './schema.js';
7+
8+
const grids = [
9+
{
10+
id: 1,
11+
values: [1, 2, 3]
12+
},
13+
{
14+
id: 2,
15+
values: [4, 5, 6]
16+
},
17+
{
18+
id: 3,
19+
values: [7, 8, 9]
20+
},
21+
]
22+
23+
export const actions: Actions = {
24+
async default({ request }) {
25+
console.log('push')
26+
grids.push({
27+
id: 3,
28+
values: [7, 8, 9]
29+
})
30+
31+
return {success: true}
32+
}
33+
}
34+
35+
export const load: PageServerLoad = async () => {
36+
const grid_forms = await Promise.all(grids.map((grid) => superValidate(grid, zod(schema), {
37+
id: grid.id.toString()
38+
})))
39+
40+
console.log(grid_forms.length)
41+
42+
return { grid_forms }
43+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script lang="ts">
2+
import { page } from '$app/stores';
3+
import type { PageData } from './$types';
4+
import { superForm } from '$lib/index.js';
5+
import Form from './Form.svelte'
6+
import { enhance } from '$app/forms';
7+
8+
let {
9+
data
10+
}: {
11+
data: PageData;
12+
} = $props();
13+
14+
const superforms = $derived(data.grid_forms.map(grid_form => superForm(grid_form, {
15+
dataType: 'json'
16+
})))
17+
</script>
18+
19+
{#each superforms as form}
20+
<Form {form}/>
21+
{/each}
22+
23+
<form method=post use:enhance>
24+
<button type=submit>Add</button>
25+
</form>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script lang="ts">
2+
import { schema } from './schema.js';
3+
import z from 'zod';
4+
import type { SuperForm } from '$lib/index.js';
5+
import SuperDebug from '$lib/index.js';
6+
7+
let {
8+
form
9+
}: {
10+
form: SuperForm<z.infer<typeof schema>>;
11+
} = $props();
12+
13+
let { form: item, enhance } = form;
14+
</script>
15+
16+
<hr />
17+
<form action="?/save" method="post" use:enhance>
18+
<SuperDebug data={$item} />
19+
</form>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { z } from 'zod';
2+
3+
export const schema = z.object({
4+
id: z.number(),
5+
values: z.number().array()
6+
});

0 commit comments

Comments
 (0)