Skip to content

Commit 2d618b5

Browse files
committed
Test added for SPA action form.
1 parent 81c11ed commit 2d618b5

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- [SPA action form](https://superforms.rocks/concepts/spa#spa-action-form) now supports form elements as well, by adding its `use:enhance` on all related forms.
13+
1014
### Fixed
1115

1216
- Fixed type inference for `FormPath` with nested arrays. Error output improved as well.
17+
- If method is "GET" or doesn't exist on an enhanced form, it's now automatically set to "POST".
1318

1419
## [2.11.0] - 2024-03-22
1520

src/routes/(v2)/v2/spa-action-2/+page.svelte

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
export let data;
99
10-
const { enhance } = superForm(defaults(valibot(classifySchema)), {
10+
const { enhance, submitting, formId } = superForm(defaults(valibot(classifySchema)), {
1111
SPA: '/v2/spa-action-2/classify',
1212
taintedMessage: false,
1313
onUpdate({ result }) {
@@ -32,12 +32,15 @@
3232
{#each data.entries as entry}
3333
<tr>
3434
<td>{entry.id}</td>
35-
<td>{entry.name}</td>
35+
<td id="name-{entry.id}">{entry.name}</td>
3636
<td>
3737
<form use:enhance>
3838
<input type="hidden" name="id" value={entry.id} />
3939
<input type="hidden" name="name" value={entry.name} />
40-
<button>Change name</button>
40+
<button on:click={() => ($formId = String(entry.id))}>
41+
{#if $submitting && $formId == String(entry.id)}Loading...
42+
{:else}Change name{/if}
43+
</button>
4144
</form>
4245
</td>
4346
</tr>

src/routes/(v2)/v2/spa-action-2/classify/+page.server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { classifySchema } from './schema.js';
44

55
export const actions = {
66
default: async ({ request }) => {
7+
await new Promise((res) => setTimeout(res, 1000));
8+
79
const form = await superValidate(request, valibot(classifySchema));
810
console.log(form);
911

0 commit comments

Comments
 (0)