File tree Expand file tree Collapse file tree 3 files changed +45
-4
lines changed
src/routes/(v2)/v2/schema-record Expand file tree Collapse file tree 3 files changed +45
-4
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { schema } from './schema.js';
44import { fail } from '@sveltejs/kit' ;
55
66export const load = async ( ) => {
7- const form = await superValidate ( zod ( schema ) ) ;
7+ const form = await superValidate ( { message : { en : 'Hi' , sv : 'Hej' } } , zod ( schema ) ) ;
88 return { form } ;
99} ;
1010
Original file line number Diff line number Diff line change 11<script lang =" ts" >
22 import { superForm } from ' $lib/client/index.js' ;
33 import SuperDebug from ' $lib/client/SuperDebug.svelte' ;
4- import RecordField from ' ./RecordField.svelte' ;
4+ import Record from ' ./Record.svelte' ;
5+ // import RecordField from './RecordField.svelte';
56
67 export let data;
78
1718{#if $message }<h4 >{$message }</h4 >{/if }
1819
1920<form method =" POST" use:enhance >
20- <RecordField field ="message.name" form ={superform } />
21- <RecordField field ="message.id" form ={superform } />
21+ <Record form ={superform } field =" message" />
22+ <!-- <RecordField field="message" form={superform} />
23+ <RecordField field="message" form={superform} /> -->
2224 <div >
2325 <button >Submit</button >
2426 </div >
Original file line number Diff line number Diff line change 1+ <script lang =" ts" context =" module" >
2+ type T = Record <string , unknown >;
3+ </script >
4+
5+ <script lang =" ts" generics =" T extends Record<string, unknown>" >
6+ import SuperDebug from ' $lib/client/SuperDebug.svelte' ;
7+ import { type SuperForm , type FormPath , fieldProxy } from ' $lib/index.js' ;
8+ import type { string } from ' joi' ;
9+ import { get , type Readable } from ' svelte/store' ;
10+
11+ export let form: SuperForm <T >;
12+ export let field: FormPath <T >;
13+
14+ const value = fieldProxy (form , field );
15+ const errors = fieldProxy (form .errors , field as any ) as unknown as Readable <
16+ Record <string , string [] | unknown >
17+ >;
18+ // $: ({ value, errors } = formFieldProxy(form, field));
19+ </script >
20+
21+ <SuperDebug data ={{ errors : $errors , message : get (form .form ).message }} />
22+
23+ {#each Object .entries ($value as Record <string , string >) as [key, data]}
24+ <label >
25+ {field }:
26+ <input name ={field } bind:value ={$value [key ]} aria-invalid ={$errors ? ' true' : undefined } />
27+ {#if $errors ?.[key ]}<span class ="invalid" >{$errors [key ]}</span >{/if }
28+ </label >
29+ {/each }
30+
31+ <style >
32+ input {
33+ background-color : #dedede ;
34+ }
35+
36+ .invalid {
37+ color : crimson ;
38+ }
39+ </style >
You can’t perform that action at this time.
0 commit comments