From d61625771eea7b8e1cb4a094a51af3167520099d Mon Sep 17 00:00:00 2001 From: April Hall Date: Sat, 22 Feb 2025 15:41:49 -0500 Subject: [PATCH] feat: 24 Char limit on channel names --- src/lib/components/forms/channelDialog.svelte | 4 +++- src/lib/types/misc.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/components/forms/channelDialog.svelte b/src/lib/components/forms/channelDialog.svelte index af78055..5de9625 100644 --- a/src/lib/components/forms/channelDialog.svelte +++ b/src/lib/components/forms/channelDialog.svelte @@ -6,10 +6,13 @@ import type { NewChannelSchema } from '$lib/types/misc'; import type { Infer, SuperValidated } from 'sveltekit-superforms'; import { superForm } from 'sveltekit-superforms'; + import { zodClient } from 'sveltekit-superforms/adapters'; + import { newChannelSchema } from '$lib/types/misc'; let open: boolean = $state(false); let { data }: { data: SuperValidated> } = $props(); const { form, errors, constraints, enhance } = superForm(data, { + validators: zodClient(newChannelSchema), onResult: ({ result }) => { if (result.type === 'success') { open = false; @@ -36,7 +39,6 @@ type="text" bind:value={$form.channelName} aria-invalid={$errors.channelName ? 'true' : undefined} - {...$constraints.channelName} /> {#if $errors.channelName}{/if} diff --git a/src/lib/types/misc.ts b/src/lib/types/misc.ts index cb6e77b..e8bc2c8 100644 --- a/src/lib/types/misc.ts +++ b/src/lib/types/misc.ts @@ -1,7 +1,7 @@ import { z } from 'zod'; export const newChannelSchema = z.object({ - channelName: z.string().min(1, 'Channel name is required'), + channelName: z.string().min(1, 'Channel name is required').max(24, 'Channel name cannot be longer than 24 characters.'), }); export type NewChannelSchema = typeof newChannelSchema;