Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fast-rooms-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: clear issues and touched states on form reset
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ export function form(id) {
await tick();

input = convert_formdata(new FormData(form));
raw_issues = [];
touched = {};
};

form.addEventListener('submit', handle_submit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
<form {...reset_id}>
<input id="reset" {...reset_id.fields.message.as('text')} />
<button>submit</button>
<button type="reset">reset</button>
</form>

{#each reset_id.fields.message.issues() as issue (issue)}
<p class="error">{issue.message}</p>
{/each}

{#if reset_id.result?.message}
<div id="result">{reset_id.result.message}</div>
{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as v from 'valibot';

export const reset_id = form(
v.object({
message: v.string()
message: v.pipe(v.string(), v.minLength(10, 'too short'))
}),
({ message }) => {
return { success: true, message };
Expand Down
13 changes: 11 additions & 2 deletions packages/kit/test/apps/async/test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@
.toBeGreaterThan(before.cleanup_count);
});

test('form reconnect updates targeted live query without reconnecting all live queries', async ({

Check warning on line 699 in packages/kit/test/apps/async/test/client.test.js

View workflow job for this annotation

GitHub Actions / test-kit (24, ubuntu-latest, chromium, current)

flaky test: form reconnect updates targeted live query without reconnecting all live queries

retries: 2
page
}) => {
await page.goto('/remote/live');
Expand Down Expand Up @@ -1107,9 +1107,18 @@

test('form submission with element id `reset` resets the form', async ({ page }) => {
await page.goto('/remote/form/reset-id');
await page.locator('[name="message"]').fill('test');
await page.locator('[name="message"]').fill('short');
await page.click('button');
await expect(page.locator('#result')).toHaveText('test');

await expect(page.locator('.error')).toHaveText('too short');

await page.click('[type="reset"]');
await expect(page.locator('.error')).toHaveCount(0);

await page.locator('[name="message"]').fill('long enough');
await page.click('button');

await expect(page.locator('#result')).toHaveText('long enough');
await expect(page.locator('[name="message"]')).toBeEmpty();
});
});
Expand Down
Loading