Skip to content

Commit 9e03f9e

Browse files
authored
fix: wait a tick before collecting form data for validation (#14631)
This way when you're doing ```ts myForm.fields.foo.set('bar') myForm.validate(); ``` you'll validate on the up-to-date data closes #14630
1 parent 82ae30f commit 9e03f9e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

.changeset/kind-emus-run.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: wait a tick before collecting form data for validation

packages/kit/src/runtime/client/remote-functions/form.svelte.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,20 @@ export function form(id) {
512512

513513
const id = ++validate_id;
514514

515+
// wait a tick in case the user is calling validate() right after set() which takes time to propagate
516+
await tick();
517+
515518
const form_data = new FormData(element, submitter);
516519

517520
/** @type {readonly StandardSchemaV1.Issue[]} */
518521
let array = [];
519522

520523
const validated = await preflight_schema?.['~standard'].validate(convert(form_data));
521524

525+
if (validate_id !== id) {
526+
return;
527+
}
528+
522529
if (validated?.issues) {
523530
array = validated.issues;
524531
} else {

0 commit comments

Comments
 (0)