You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30-13Lines changed: 30 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ Svelte-Command-Form allows you to have easy to use forms with commands instead o
5
5
## Features
6
6
7
7
-**Schema-agnostic validation** – Works with any library that implements the Standard Schema v1 interface (Zod, Valibot, TypeBox, custom validators, …).
8
-
-**Command-first workflow** – Wire forms directly to your remote command (e.g. [`command` from `$app/server`](https://kit.svelte.dev/docs/load#command-functions)), and let the helper manage submission, success, and error hooks.
8
+
-**Command-first workflow** – Wire forms directly to your remote command ([`command` from `$app/server`](https://kit.svelte.dev/docs/load#command-functions)), and let the helper manage submission, success, and error hooks.
9
9
-**Typed form state** – `form`, `errors`, and `issues` are all strongly typed from your schema, so your component code stays in sync with validation rules.
10
10
-**Friendly + raw errors** – Surface user-friendly `errors` for rendering, while also exposing the untouched validator `issues` array for logging/analytics.
11
11
-**Helpers for remote inputs** – Includes `normalizeFiles` for bundling file uploads and `standardValidate` for reusing schema validation outside the form class.
@@ -182,7 +182,7 @@ Both the Zod and Valibot schemas above can be adapted to accept either `File[]`
182
182
183
183
## Initial values and schema defaults
184
184
185
-
Standard Schema v1 intentionally does **not** provide a cross-library location for default values. A Zod or Valibot schema may specify defaults internally, but those defaults are not discoverable through the shared `~standard` interface. Because of that, `CommandForm` cannot pull defaults from your schema automatically. Instead, pass defaults via `options.initial`:
185
+
Standard Schema v1 does **not** provide a cross-library location for default values. A Zod or Valibot schema may specify defaults internally, but those defaults are not discoverable through the shared `~standard` interface. If there is an easy way to do this feel free to submit a PR. Because of that, `CommandForm` cannot pull defaults from your schema automatically. Instead, pass defaults via `options.initial`:
186
186
187
187
```ts
188
188
const form =newCommandForm(userSchema, {
@@ -201,21 +201,38 @@ When validation fails, `CommandForm`:
201
201
2. Converts issues into `errors` (per field) via `transformIssues`.
202
202
3. Stores the raw issue array in `issues` for programmatic access.
203
203
204
-
If the command throws an `HttpError` from SvelteKit, the helper looks for `err.body.issues` and merges them into the same structures. Any other error is forwarded to `onError` after clearing submission state.
204
+
If the command throws an `HttpError` from SvelteKit, the helper looks for `err.body.issues` and merges them into the same structures. Any other error is forwarded to `onError` after clearing submission state. You can handle validation errors to populate this in your `hooks.server.ts`
205
205
206
-
## Development
206
+
## Manual Errors
207
207
208
-
-`pnpm dev` – Play with the demo app in `src/routes`.
209
-
-`pnpm check` – Run `svelte-check` for type and accessibility diagnostics.
210
-
-`pnpm test` – Execute the Vitest suite (if present).
211
-
-`pnpm prepack` – Builds the library with `svelte-package` + `publint` (also run as part of `pnpm build`).
208
+
You can add errors manually by using the `addErrors` method on the client or by throwing a `new SchemaValidationError` inside of the remote function.
212
209
213
-
## Publishing
210
+
```typescript
211
+
// server add error
212
+
const someFunc =command(schema, async (data) => {
213
+
const user =awaitdb.find({where: email: data.email})
214
+
if(!user) thrownewSchemaValidationError([{ message: "User does with this email does not exist!", path: ['email'] }])
3. Inspect the output (`npm pack --dry-run`) if desired.
218
-
4. Publish: `npm publish` (or `pnpm publish`).
235
+
Feel free to contribute by opening a PR with a detailed description of why you are wanting to change what you are changing. If it can be tested with Vitest, that is preferred.
0 commit comments