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 1
1
<script lang =" ts" >
2
- import { superForm } from ' $lib/client/index .js' ;
2
+ import { valibot } from ' $lib/adapters/valibot .js' ;
3
3
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' ;
4
7
5
8
export let data;
6
9
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' ;
16
17
}
17
- );
18
+ } );
18
19
</script >
19
20
20
21
<SuperDebug data ={data .entries } />
Original file line number Diff line number Diff line change 1
1
import { 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' ;
9
4
10
5
export const actions = {
11
6
default : async ( { request } ) => {
12
- const form = await superValidate ( request , valibot ( _classifySchema ) ) ;
7
+ const form = await superValidate ( request , valibot ( classifySchema ) ) ;
13
8
console . log ( form ) ;
14
9
15
10
if ( ! form . valid ) return fail ( 400 , { form } ) ;
16
11
17
- return message ( form , { id : form . data . id } ) ;
12
+ return { form, posted : form . data . id } ;
18
13
}
19
14
} ;
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