File tree Expand file tree Collapse file tree 4 files changed +53
-0
lines changed Expand file tree Collapse file tree 4 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 3434 </li >
3535 <li ><a href =" /tests/array-component" >Array proxy</a ></li >
3636 <li ><a href =" /tests/redirect-same-route" >Redirect with delay</a ></li >
37+ <li ><a href =" /tests/strict-mode" >Strict mode</a ></li >
3738 </ul >
3839</nav >
3940
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+ const formData = await request . formData ( ) ;
13+ console . log ( formData ) ;
14+
15+ const form = await superValidate ( formData , schema , { strict : true } ) ;
16+ console . log ( 'POST' , form ) ;
17+
18+ if ( ! form . valid ) return fail ( 400 , { form } ) ;
19+
20+ return message ( form , 'Posted OK!' ) ;
21+ }
22+ } ;
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 { errors, enhance } = superForm (data .form );
8+ </script >
9+
10+ <form method =" POST" use:enhance >
11+ {#if $errors .name }<span class ="invalid" >{$errors .name }</span >{/if }
12+ <div >
13+ <button >Submit</button >
14+ </div >
15+ </form >
16+
17+ <style lang =" scss" >
18+ form {
19+ margin : 2rem 0 ;
20+
21+ .invalid {
22+ color : crimson ;
23+ }
24+ }
25+ </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 )
5+ } ) ;
You can’t perform that action at this time.
0 commit comments