A demo project showcasing smart client-side form validation in SvelteKit using Zod and shadcn-svelte UI components.
This project demonstrates how to build a maintainable, schema-based validation system with real-world UX patterns — without relying on heavy form libraries.
z.coerceInstead of validating only on submit or on every keystroke, this project implements a smarter UX pattern:
superRefineThis approach:
npx sv create svelte-form-validation --add tailwindcss
cd svelte-form-validation
npx shadcn-svelte@latest init
npx shadcn-svelte@latest add button
npx shadcn-svelte@latest add input
npx shadcn-svelte@latest add field
npx shadcn-svelte@latest add textarea
npx shadcn-svelte@latest add checkbox
npm install zod
npm run dev
src/
├─ lib/
│ ├─ components/
│ ├─ form-configs/
│ │ └─ form-schema.ts # Zod schema definitions
├─ routes/
│ └─ +page.svelte # Form implementation
The project separates validation logic into:
registerBaseSchema → Independent field validationregisterSchema → Cross-field validation via superRefineThis allows:
safeParse for controlled validationschema.picktouched state objectz.coerce.number()
This repository accompanies the article:
"How to Build UX-Friendly Form Validation in SvelteKit with Zod" : https://dev.to/kokumubooker/how-to-build-ux-friendly-form-validation-in-sveltekit-with-zod-130k