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
feat: return boolean from submit to indicate submission validity (#15530)
With this PR, a `submit` in an enhanced remote `form` returns a boolean
indicating whether it was valid or not:
```js
try {
if (await submit()) {
// success (return or redirect)
} else {
// validation error
}
} catch (e) {
// something went wrong
}
```
The alternative approach we considered was to throw an error on invalid
data. But that feels more cumbersome, since now you need to
differentiate between different error types:
```js
import { isHttpError } from '@sveltejs/kit';
// later
try {
await submit();
// success (return or redirect)
} catch (e) {
if (isHttpError(e, 400)) {
// validation error
} else {
// something went wrong
}
}
```
---
### Please don't delete this checklist! Before submitting the PR, please
make sure you do the following:
- [ ] It's really useful if your PR references an issue where it is
discussed ahead of time. In many cases, features are absent for a
reason. For large changes, please create an RFC:
https://github.com/sveltejs/rfcs
- [x] This message body should clearly illustrate what problems it
solves.
- [x] Ideally, include a test that fails without this PR but passes with
it.
### Tests
- [x] Run the tests with `pnpm test` and lint the project with `pnpm
lint` and `pnpm check`
### Changesets
- [x] If your PR makes a change that should be noted in one or more
packages' changelogs, generate a changeset by running `pnpm changeset`
and following the prompts. Changesets that add features should be
`minor` and those that fix bugs should be `patch`. Please prefix
changeset messages with `feat:`, `fix:`, or `chore:`.
### Edits
- [x] Please ensure that 'Allow edits from maintainers' is checked. PRs
without this option may be closed.
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Tee Ming <[email protected]>
0 commit comments