Skip to content

Commit

Permalink
docs: updated sveltekit usage
Browse files Browse the repository at this point in the history
  • Loading branch information
GauBen committed Oct 25, 2024
1 parent cbf2062 commit f038428
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img src="https://raw.githubusercontent.com/GauBen/formgator/refs/heads/main/formgator.jpg" alt="Ali, the friendly alligator that guards your forms" width="200" height="200">
</div>

# formgator
# Formgator

A validation library for JavaScript `FormData` and `URLSearchParams` objects.

Expand Down Expand Up @@ -187,9 +187,16 @@ If some fields were accepted nonetheless, the `error` object will have an `accep

## Usage with SvelteKit

Formgator can be used in SvelteKit to validate form data and query parameters. Because formgator imports `@sveltejs/kit` internally, you need to bundle it with your application to avoid weird runtime behaviors:

- Move `formgator` from `dependencies` to `devDependencies` in your `package.json`.
- Add `ssr: { noExternal: ['formgator'] }` to the root of `vite.config.{js|ts}`.

This will ensure that formgator use the bundled version of `@sveltejs/kit` instead of an external one. This also means that formgator will be tree-shaken in your production build, and no longer imported from `node_modules` at runtime.

### Form actions

`formgator` exposes a SvelteKit adapter that can be used to validate form data in SvelteKit [form actions](https://kit.svelte.dev/docs/form-actions).
Formgator exposes a SvelteKit adapter that can be used to validate form data in SvelteKit [form actions](https://kit.svelte.dev/docs/form-actions).

```ts
// +page.server.ts
Expand Down

0 comments on commit f038428

Please sign in to comment.