Skip to content

Commit 3f87795

Browse files
committed
[sveltekit] Fix form reset after success submit
1 parent 487df96 commit 3f87795

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

packages/sveltekit/src/lib/client/create-form.svelte.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ export function createSvelteKitForm<
7979
| ValidatedFormData<E, Meta['__sendData']>
8080
| undefined;
8181
if (validationData !== undefined) {
82-
return {
83-
schema: options.schema ?? page.data[meta.name].schema,
84-
initialValue: validationData.data,
85-
initialErrors: validationData.errors
86-
};
82+
return validationData.isValid
83+
? page.data[meta.name]
84+
: {
85+
schema: options.schema ?? page.data[meta.name].schema,
86+
initialValue: validationData.data,
87+
initialErrors: validationData.errors
88+
};
8789
}
8890
} else {
8991
return page.data[meta.name];
@@ -163,7 +165,7 @@ export function createSvelteKitForm<
163165
const form = createForm3(
164166
new Proxy(options, {
165167
has(target, p) {
166-
return Reflect.has(target, p) || p in defaults
168+
return Reflect.has(target, p) || p in defaults;
167169
},
168170
get(target, p, receiver) {
169171
if (!(p in target)) {
@@ -183,7 +185,7 @@ export function createSvelteKitForm<
183185
if (validationData === undefined) {
184186
return;
185187
}
186-
if (validationData.sendData) {
188+
if (validationData.sendData && form.isSubmitted) {
187189
form.formValue = validationData.data;
188190
}
189191
form.errors = groupErrors(validationData.errors);

packages/sveltekit/src/routes/+page.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const actions = {
5252
schema,
5353
validator,
5454
data,
55+
sendData: true
5556
})
5657
};
5758
},

0 commit comments

Comments
 (0)