Skip to content

Commit 81c11ed

Browse files
committed
Another test for SPA action form
1 parent 456cef4 commit 81c11ed

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

src/routes/(v2)/v2/spa-action-2/+page.svelte

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
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} />
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
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';
94

105
export 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
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
});

0 commit comments

Comments
 (0)