File tree Expand file tree Collapse file tree 3 files changed +22
-20
lines changed
src/routes/(v2)/v2/spa-action-2 Expand file tree Collapse file tree 3 files changed +22
-20
lines changed Original file line number Diff line number Diff line change 11<script lang =" ts" >
2- import { superForm } from ' $lib/client/index .js' ;
2+ import { valibot } from ' $lib/adapters/valibot .js' ;
33 import SuperDebug from ' $lib/client/SuperDebug.svelte' ;
4+ import { defaults , superForm } from ' $lib/index.js' ;
5+ import type { ActionData } from ' ./classify/$types.js' ;
6+ import { classifySchema } from ' ./classify/schema.js' ;
47
58 export let data;
69
7- const { enhance } = superForm (
8- {},
9- {
10- SPA: ' /v2/spa-action-2/classify' ,
11- taintedMessage: false ,
12- onUpdate({ form }) {
13- const entry = data .entries .find ((e ) => e .id == form .message .id );
14- if (entry ) entry .name = ' Modified' ;
15- }
10+ const { enhance } = superForm (defaults (valibot (classifySchema )), {
11+ SPA: ' /v2/spa-action-2/classify' ,
12+ taintedMessage: false ,
13+ onUpdate({ result }) {
14+ const status = result .data as NonNullable <ActionData >;
15+ const entry = data .entries .find ((e ) => e .id == status .posted );
16+ if (entry ) entry .name = ' Modified' ;
1617 }
17- );
18+ } );
1819 </script >
1920
2021<SuperDebug data ={data .entries } />
Original file line number Diff line number Diff line change 11import { valibot } from '$lib/adapters/valibot.js' ;
2- import { fail , message , superValidate } from '$lib/index.js' ;
3- import * as v from 'valibot' ;
4-
5- export const _classifySchema = v . object ( {
6- id : v . number ( [ v . minValue ( 1 ) ] ) ,
7- name : v . string ( )
8- } ) ;
2+ import { fail , superValidate } from '$lib/index.js' ;
3+ import { classifySchema } from './schema.js' ;
94
105export const actions = {
116 default : async ( { request } ) => {
12- const form = await superValidate ( request , valibot ( _classifySchema ) ) ;
7+ const form = await superValidate ( request , valibot ( classifySchema ) ) ;
138 console . log ( form ) ;
149
1510 if ( ! form . valid ) return fail ( 400 , { form } ) ;
1611
17- return message ( form , { id : form . data . id } ) ;
12+ return { form, posted : form . data . id } ;
1813 }
1914} ;
Original file line number Diff line number Diff line change 1+ import * as v from 'valibot' ;
2+
3+ export const classifySchema = v . object ( {
4+ id : v . number ( [ v . minValue ( 1 ) ] ) ,
5+ name : v . string ( )
6+ } ) ;
You can’t perform that action at this time.
0 commit comments