File tree Expand file tree Collapse file tree 3 files changed +61
-0
lines changed
src/routes/tests/proxy-in-proxy Expand file tree Collapse file tree 3 files changed +61
-0
lines changed 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 ) ;
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 { dateProxy , formFieldProxy , superForm } from ' $lib/client' ;
3+ import type { PageData } from ' ./$types' ;
4+
5+ export let data: PageData ;
6+
7+ const theForm = superForm (data .form );
8+ const { errors } = formFieldProxy (theForm , ' date' );
9+ const date = dateProxy (theForm .form , ' date' , { format: ' date' });
10+ </script >
11+
12+ <form method =" POST" use:theForm .enhance >
13+ <label >
14+ Date: <input name ="date" type ="date" bind:value ={$date } />
15+ {#if $errors }<span class ="invalid" >{$errors }</span >{/if }
16+ </label >
17+ <div >
18+ <button >Submit</button >
19+ </div >
20+ </form >
21+
22+ <style lang =" scss" >
23+ form {
24+ margin : 2rem 0 ;
25+
26+ input {
27+ background-color : #dedede ;
28+ }
29+
30+ .invalid {
31+ color : crimson ;
32+ }
33+ }
34+ </style >
Original file line number Diff line number Diff line change 1+ import { z } from 'zod' ;
2+
3+ export const schema = z . object ( {
4+ date : z . date ( )
5+ } ) ;
You can’t perform that action at this time.
0 commit comments