File tree Expand file tree Collapse file tree 5 files changed +83
-4
lines changed Expand file tree Collapse file tree 5 files changed +83
-4
lines changed Original file line number Diff line number Diff line change 44 <a href =" /crud" >CRUD</a > |
55 <a href =" /super-debug" >SuperDebug</a > |
66 <a href =" /nested" >Nested</a > |
7+ <a href =" /timers" >Timers</a > |
78 <a href =" /multiple" >Multiple</a >
89 <br />
910 <a href =" /multiple2" >Multiple 2</a > |
Original file line number Diff line number Diff line change 1- import type { Actions , PageServerLoad } from './$types' ;
21import { message , superValidate } from '$lib/server' ;
32import { schema } from './schema' ;
43import { fail } from '@sveltejs/kit' ;
54
6- export const load = ( async ( ) => {
5+ export const load = async ( ) => {
76 const form = await superValidate ( schema ) ;
87 return { form } ;
9- } ) satisfies PageServerLoad ;
8+ } ;
109
1110export const actions = {
1211 default : async ( { request } ) => {
@@ -20,4 +19,4 @@ export const actions = {
2019
2120 return message ( form , 'Posted OK!' ) ;
2221 }
23- } satisfies Actions ;
22+ } ;
Original file line number Diff line number Diff line change 1+ import { message , superValidate } from '$lib/server' ;
2+ import { schema } from './schema' ;
3+ import { fail } from '@sveltejs/kit' ;
4+
5+ export const load = async ( ) => {
6+ const form = await superValidate ( schema ) ;
7+ return { form } ;
8+ } ;
9+
10+ export const actions = {
11+ default : async ( { request } ) => {
12+ await new Promise ( ( r ) => setTimeout ( r , 12000 ) ) ;
13+ const form = await superValidate ( request , schema ) ;
14+
15+ if ( ! form . valid ) return fail ( 400 , { form } ) ;
16+
17+ return message ( form , 'Posted OK!' ) ;
18+ }
19+ } ;
Original file line number Diff line number Diff line change 1+ <script lang =" ts" >
2+ import { superForm } from ' $lib/client' ;
3+ import type { PageData } from ' ./$types' ;
4+
5+ export let data: PageData ;
6+
7+ const {
8+ form,
9+ errors,
10+ tainted,
11+ message,
12+ enhance,
13+ submitting,
14+ delayed,
15+ timeout
16+ } = superForm (data .form , {
17+ delayMs: 4000 ,
18+ timeoutMs: 8000
19+ });
20+ </script >
21+
22+ {#if $message }<h4 >{$message }</h4 >{/if }
23+
24+ <form method =" POST" use:enhance >
25+ <label >
26+ Name: <input name ="name" bind:value ={$form .name } />
27+ {#if $errors .name }<span class ="invalid" >{$errors .name }</span >{/if }
28+ </label >
29+ <div >
30+ <button >Submit</button >
31+ <div >
32+ {#if $timeout }
33+ STATE-TIMEOUT
34+ {:else if $delayed }
35+ STATE-DELAYED
36+ {:else if $submitting }
37+ STATE-SUBMITTING
38+ {/if }
39+ </div >
40+ </div >
41+ </form >
42+
43+ <style lang =" scss" >
44+ form {
45+ margin : 2rem 0 ;
46+
47+ input {
48+ background-color : #dedede ;
49+ }
50+
51+ .invalid {
52+ color : crimson ;
53+ }
54+ }
55+ </style >
Original file line number Diff line number Diff line change 1+ import { z } from 'zod' ;
2+
3+ export const schema = z . object ( {
4+ name : z . string ( ) . min ( 1 ) . default ( 'Name' )
5+ } ) ;
You can’t perform that action at this time.
0 commit comments