File tree Expand file tree Collapse file tree 4 files changed +93
-0
lines changed
src/routes/(v2)/v2/component-ondestroy Expand file tree Collapse file tree 4 files changed +93
-0
lines changed Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 1+ import { z } from 'zod' ;
2+
3+ export const schema = z . object ( {
4+ id : z . number ( ) ,
5+ values : z . number ( ) . array ( )
6+ } ) ;
You can’t perform that action at this time.
0 commit comments