Skip to content

Commit f797e81

Browse files
Sync kit docs (#1731)
sync kit docs Co-authored-by: svelte-docs-bot[bot] <196124396+svelte-docs-bot[bot]@users.noreply.github.com>
1 parent efb95dd commit f797e81

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

apps/svelte.dev/content/docs/kit/20-core-concepts/60-remote-functions.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,10 @@ Alternatively, you could use `select` and `select multiple`:
455455
456456
### Programmatic validation
457457
458-
In addition to declarative schema validation, you can programmatically mark fields as invalid inside the form handler using the `invalid` function. This is useful for cases where you can't know if something is valid until you try to perform some action. Just like `redirect` or `error`, `invalid` throws. It expects a list of strings (for issues relating to the form as a whole) or standard-schema-compliant issues (for those relating to a specific field). Use the `issue` parameter for type-safe creation of such issues:
458+
In addition to declarative schema validation, you can programmatically mark fields as invalid inside the form handler using the `invalid` helper from `@sveltejs/kit`. This is useful for cases where you can't know if something is valid until you try to perform some action.
459+
460+
- It throws just like `redirect` or `error`
461+
- It accepts multiple arguments that can be strings (for issues relating to the form as a whole — these will only show up in `fields.allIssues()`) or standard-schema-compliant issues (for those relating to a specific field). Use the `issue` parameter for type-safe creation of such issues:
459462
460463
```js
461464
/// file: src/routes/shop/data.remote.js
@@ -485,12 +488,6 @@ export const buyHotcakes = form(
485488
);
486489
```
487490
488-
The `invalid` function works as both a function and a proxy:
489-
490-
- Call `invalid(issue1, issue2, ...issueN)` to throw a validation error
491-
- If an issue is a `string`, it applies to the form as a whole (and will show up in `fields.allIssues()`)
492-
- Use `invalid.fieldName(message)` to create an issue for a specific field. Like `fields` this is type-safe and you can use regular property access syntax to create issues for deeply nested objects (e.g. `invalid.profile.email('Email already exists')` or `invalid.items[0].qty('Insufficient stock')`)
493-
494491
### Validation
495492
496493
If the submitted data doesn't pass the schema, the callback will not run. Instead, each invalid field's `issues()` method will return an array of `{ message: string }` objects, and the `aria-invalid` attribute (returned from `as(...)`) will be set to `true`:

0 commit comments

Comments
 (0)