diff --git a/apps/www/src/lib/registry/default/example/checkbox-form-multiple.svelte b/apps/www/src/lib/registry/default/example/checkbox-form-multiple.svelte index 69a38d607..b018284b4 100644 --- a/apps/www/src/lib/registry/default/example/checkbox-form-multiple.svelte +++ b/apps/www/src/lib/registry/default/example/checkbox-form-multiple.svelte @@ -70,7 +70,7 @@ } -
+
Sidebar diff --git a/apps/www/src/lib/registry/default/example/checkbox-form-single.svelte b/apps/www/src/lib/registry/default/example/checkbox-form-single.svelte index 1b8146611..c4f37f820 100644 --- a/apps/www/src/lib/registry/default/example/checkbox-form-single.svelte +++ b/apps/www/src/lib/registry/default/example/checkbox-form-single.svelte @@ -31,7 +31,7 @@ const { form: formData, enhance } = form; - + - + diff --git a/apps/www/src/lib/registry/default/example/date-picker-form.svelte b/apps/www/src/lib/registry/default/example/date-picker-form.svelte index 79f153025..d03b3a73c 100644 --- a/apps/www/src/lib/registry/default/example/date-picker-form.svelte +++ b/apps/www/src/lib/registry/default/example/date-picker-form.svelte @@ -57,7 +57,7 @@ let placeholder: DateValue = today(getLocalTimeZone()); - + Date of birth diff --git a/apps/www/src/lib/registry/default/example/form-demo.svelte b/apps/www/src/lib/registry/default/example/form-demo.svelte index 2135a0e12..e07fee9bd 100644 --- a/apps/www/src/lib/registry/default/example/form-demo.svelte +++ b/apps/www/src/lib/registry/default/example/form-demo.svelte @@ -31,7 +31,7 @@ const { form: formData, enhance } = form; - + Username diff --git a/apps/www/src/lib/registry/default/example/radio-group-form.svelte b/apps/www/src/lib/registry/default/example/radio-group-form.svelte index 816820022..ef435e8f3 100644 --- a/apps/www/src/lib/registry/default/example/radio-group-form.svelte +++ b/apps/www/src/lib/registry/default/example/radio-group-form.svelte @@ -35,7 +35,7 @@ const { form: formData, enhance } = form; - + Notify me about... diff --git a/apps/www/src/lib/registry/default/example/select-form.svelte b/apps/www/src/lib/registry/default/example/select-form.svelte index 64d45a6da..42f396f4c 100644 --- a/apps/www/src/lib/registry/default/example/select-form.svelte +++ b/apps/www/src/lib/registry/default/example/select-form.svelte @@ -40,7 +40,7 @@ : undefined; - + Email diff --git a/apps/www/src/lib/registry/default/example/switch-form.svelte b/apps/www/src/lib/registry/default/example/switch-form.svelte index aeda89b6f..963b53499 100644 --- a/apps/www/src/lib/registry/default/example/switch-form.svelte +++ b/apps/www/src/lib/registry/default/example/switch-form.svelte @@ -32,7 +32,7 @@ const { form: formData, enhance } = form; - +
Email Notifications
diff --git a/apps/www/src/lib/registry/default/example/textarea-form.svelte b/apps/www/src/lib/registry/default/example/textarea-form.svelte index e238307db..77176bb2a 100644 --- a/apps/www/src/lib/registry/default/example/textarea-form.svelte +++ b/apps/www/src/lib/registry/default/example/textarea-form.svelte @@ -35,7 +35,7 @@ const { form: formData, enhance } = form; - + Bio diff --git a/apps/www/src/lib/registry/new-york/example/checkbox-form-multiple.svelte b/apps/www/src/lib/registry/new-york/example/checkbox-form-multiple.svelte index 01696c7bc..c90777c68 100644 --- a/apps/www/src/lib/registry/new-york/example/checkbox-form-multiple.svelte +++ b/apps/www/src/lib/registry/new-york/example/checkbox-form-multiple.svelte @@ -69,7 +69,7 @@ } - +
Sidebar diff --git a/apps/www/src/lib/registry/new-york/example/checkbox-form-single.svelte b/apps/www/src/lib/registry/new-york/example/checkbox-form-single.svelte index d519fe59a..351d9684d 100644 --- a/apps/www/src/lib/registry/new-york/example/checkbox-form-single.svelte +++ b/apps/www/src/lib/registry/new-york/example/checkbox-form-single.svelte @@ -31,7 +31,7 @@ const { form: formData, enhance } = form; - + - + diff --git a/apps/www/src/lib/registry/new-york/example/date-picker-form.svelte b/apps/www/src/lib/registry/new-york/example/date-picker-form.svelte index 43e8c46e0..daef49315 100644 --- a/apps/www/src/lib/registry/new-york/example/date-picker-form.svelte +++ b/apps/www/src/lib/registry/new-york/example/date-picker-form.svelte @@ -57,7 +57,7 @@ let placeholder: DateValue = today(getLocalTimeZone()); - + Date of birth diff --git a/apps/www/src/lib/registry/new-york/example/form-demo.svelte b/apps/www/src/lib/registry/new-york/example/form-demo.svelte index e35a26dc2..2f3432421 100644 --- a/apps/www/src/lib/registry/new-york/example/form-demo.svelte +++ b/apps/www/src/lib/registry/new-york/example/form-demo.svelte @@ -32,7 +32,7 @@ const { form: formData, enhance } = form; - + Username diff --git a/apps/www/src/lib/registry/new-york/example/radio-group-form.svelte b/apps/www/src/lib/registry/new-york/example/radio-group-form.svelte index c94b47f09..95682f462 100644 --- a/apps/www/src/lib/registry/new-york/example/radio-group-form.svelte +++ b/apps/www/src/lib/registry/new-york/example/radio-group-form.svelte @@ -35,7 +35,7 @@ const { form: formData, enhance } = form; - + Notify me about... diff --git a/apps/www/src/lib/registry/new-york/example/select-form.svelte b/apps/www/src/lib/registry/new-york/example/select-form.svelte index c2371f27d..d7a7e54ed 100644 --- a/apps/www/src/lib/registry/new-york/example/select-form.svelte +++ b/apps/www/src/lib/registry/new-york/example/select-form.svelte @@ -40,7 +40,7 @@ : undefined; - + Email diff --git a/apps/www/src/lib/registry/new-york/example/switch-form.svelte b/apps/www/src/lib/registry/new-york/example/switch-form.svelte index d97bd78d4..0ca0b868d 100644 --- a/apps/www/src/lib/registry/new-york/example/switch-form.svelte +++ b/apps/www/src/lib/registry/new-york/example/switch-form.svelte @@ -32,7 +32,7 @@ const { form: formData, enhance } = form; - +
Email Notifications
diff --git a/apps/www/src/lib/registry/new-york/example/textarea-form.svelte b/apps/www/src/lib/registry/new-york/example/textarea-form.svelte index 13ea589f4..81170b2e4 100644 --- a/apps/www/src/lib/registry/new-york/example/textarea-form.svelte +++ b/apps/www/src/lib/registry/new-york/example/textarea-form.svelte @@ -35,7 +35,7 @@ const { form: formData, enhance } = form; - + Bio diff --git a/apps/www/src/routes/+page.server.ts b/apps/www/src/routes/+page.server.ts index d1aa2995a..dc5b23a16 100644 --- a/apps/www/src/routes/+page.server.ts +++ b/apps/www/src/routes/+page.server.ts @@ -1,4 +1,42 @@ -import type { PageServerLoad } from "./$types.js"; +import { fail } from "@sveltejs/kit"; +import { zod } from "sveltekit-superforms/adapters"; +import { superValidate } from "sveltekit-superforms"; +import type { Actions, RequestEvent, PageServerLoad } from "./$types.js"; +import type { AnyZodObject } from "zod"; + +import { formSchema } from "$lib/registry/default/example/form-demo.svelte"; +import { formSchema as checkboxSingleSchema } from "$lib/registry/default/example/checkbox-form-single.svelte"; +import { formSchema as radioGroupSchema } from "$lib/registry/default/example/radio-group-form.svelte"; +import { formSchema as selectSchema } from "$lib/registry/default/example/select-form.svelte"; +import { formSchema as switchSchema } from "$lib/registry/default/example/switch-form.svelte"; +import { formSchema as textareaSchema } from "$lib/registry/default/example/textarea-form.svelte"; +import { formSchema as comboboxFormSchema } from "$lib/registry/default/example/combobox-form.svelte"; +import { formSchema as datePickerFormSchema } from "$lib/registry/default/example/date-picker-form.svelte"; +import { formSchema as checkboxMultipleSchema } from "$lib/registry/default/example/checkbox-form-multiple.svelte"; + +export const actions: Actions = { + username: async (e) => handleForm(e, formSchema), + checkboxSingle: async (e) => handleForm(e, checkboxSingleSchema), + checkboxMultiple: async (e) => handleForm(e, checkboxMultipleSchema), + radioGroup: async (e) => handleForm(e, radioGroupSchema), + select: async (e) => handleForm(e, selectSchema), + switch: async (e) => handleForm(e, switchSchema), + textarea: async (e) => handleForm(e, textareaSchema), + combobox: async (e) => handleForm(e, comboboxFormSchema), + datePicker: async (e) => handleForm(e, datePickerFormSchema), +}; + +async function handleForm(event: RequestEvent, schema: AnyZodObject) { + const form = await superValidate(event, zod(schema)); + if (!form.valid) { + return fail(400, { + form, + }); + } + return { + form, + }; +} export const load: PageServerLoad = async (event) => { const layoutCookie = event.cookies.get("PaneForge:layout"); diff --git a/apps/www/src/routes/docs/+page.server.ts b/apps/www/src/routes/docs/+page.server.ts deleted file mode 100644 index 5b8269962..000000000 --- a/apps/www/src/routes/docs/+page.server.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { fail } from "@sveltejs/kit"; -import { zod } from "sveltekit-superforms/adapters"; -import { superValidate } from "sveltekit-superforms"; -import type { Actions, RequestEvent } from "./$types.js"; -import type { AnyZodObject } from "zod"; - -import { formSchema } from "$lib/registry/default/example/form-demo.svelte"; -import { formSchema as checkboxSingleSchema } from "$lib/registry/default/example/checkbox-form-single.svelte"; -import { formSchema as radioGroupSchema } from "$lib/registry/default/example/radio-group-form.svelte"; -import { formSchema as selectSchema } from "$lib/registry/default/example/select-form.svelte"; -import { formSchema as switchSchema } from "$lib/registry/default/example/switch-form.svelte"; -import { formSchema as textareaSchema } from "$lib/registry/default/example/textarea-form.svelte"; -import { formSchema as comboboxFormSchema } from "$lib/registry/default/example/combobox-form.svelte"; -import { formSchema as datePickerFormSchema } from "$lib/registry/default/example/date-picker-form.svelte"; -import { formSchema as checkboxMultipleSchema } from "$lib/registry/default/example/checkbox-form-multiple.svelte"; - -export const prerender = false; - -export const actions: Actions = { - username: async (e) => handleForm(e, formSchema), - checkboxSingle: async (e) => handleForm(e, checkboxSingleSchema), - checkboxMultiple: async (e) => handleForm(e, checkboxMultipleSchema), - radioGroup: async (e) => handleForm(e, radioGroupSchema), - select: async (e) => handleForm(e, selectSchema), - switch: async (e) => handleForm(e, switchSchema), - textarea: async (e) => handleForm(e, textareaSchema), - combobox: async (e) => handleForm(e, comboboxFormSchema), - datePicker: async (e) => handleForm(e, datePickerFormSchema), -}; - -async function handleForm(event: RequestEvent, schema: AnyZodObject) { - const form = await superValidate(event, zod(schema)); - if (!form.valid) { - return fail(400, { - form, - }); - } - return { - form, - }; -}