Skip to content

Commit 02667f2

Browse files
committed
invalidateAll: force now updates the reset data to the latest load function data.
1 parent e317457 commit 02667f2

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Type narrowing for `FormPath` and its relatives, to filter the paths based on a specific type, like `FormPath<T, Date>`.
1313
- Proxy types: `FieldProxy`, `FormFieldProxy` and `ArrayProxy`.
14-
- `invalidateAll` option `force`, to always use the load function form data, instead of the one returned from the form action. Useful when updating the form data partially, to ensure that the data is refreshed from the server.
14+
- `invalidateAll` option `force`, to always use the load function form data, instead of the one returned from the form action. Useful when updating the form data partially, to ensure that the data is refreshed from the server. It also bases the `reset` function on the latest load function value returned.
1515

1616
### Fixed
1717

src/lib/client/superForm.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,10 @@ export function superForm<
13271327
continue;
13281328
}
13291329

1330+
if (options.invalidateAll === 'force') {
1331+
initialForm.data = newForm.data as T;
1332+
}
1333+
13301334
rebind({
13311335
form: newForm as SuperValidated<T, M, In>,
13321336
untaint: successResult,

src/routes/(v2)/v2/issue-358/+page.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
// eslint-disable-next-line svelte/valid-compile
99
const resetForm = $page.url.searchParams.has('reset');
1010
11-
const { form, errors, message, enhance } = superForm(data.form, {
11+
const { form, errors, message, enhance, reset, tainted } = superForm(data.form, {
1212
invalidateAll: 'force',
1313
resetForm
1414
});
1515
</script>
1616

17-
<SuperDebug data={$form} />
17+
<SuperDebug data={{ $form, $tainted }} />
1818

1919
<h3>Superforms testing ground - Zod</h3>
2020

@@ -43,6 +43,7 @@
4343
</label>
4444

4545
<button>Submit</button>
46+
<button type="button" on:click={() => reset()} style="background-color: darkred">Reset</button>
4647
</form>
4748

4849
<hr />

0 commit comments

Comments
 (0)