Skip to content

Commit 136121a

Browse files
committed
Reverted form argument in onError
Breaks existing code that updates stores. Wait until v3 for this feature.
1 parent 0330389 commit 136121a

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Exported `ClientValidationAdapter` from `sveltekit-supoerforms/adapters`.
13-
- `form` is now available as an argument in [onError](https://superforms.rocks/concepts/events#onerror), so it can be modified as in `onUpdate`.
1413

1514
### Fixed
1615

src/lib/client/superForm.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ export type FormOptions<
144144
onError:
145145
| 'apply'
146146
| ((event: {
147-
form: SuperValidated<T, M, In>;
148147
result: {
149148
type: 'error';
150149
status?: number;
@@ -1495,6 +1494,9 @@ export function superForm<
14951494
if (options.applyAction && pageUpdate.form && typeof pageUpdate.form === 'object') {
14961495
const actionData = pageUpdate.form;
14971496

1497+
// If actionData is an error, it's sent here from triggerOnError
1498+
if (actionData.type === 'error') return;
1499+
14981500
for (const newForm of Context_findValidationForms(actionData)) {
14991501
const isInitial = initialForms.has(newForm);
15001502

@@ -1703,7 +1705,8 @@ export function superForm<
17031705
result: { type: 'error'; status?: number; error: any },
17041706
status: number
17051707
) {
1706-
const form: SuperValidated<T, M, In> = Form_capture(false);
1708+
// For v3, then return { form } as data in applyAction below:
1709+
//const form: SuperValidated<T, M, In> = Form_capture(false);
17071710

17081711
result.status = status;
17091712

@@ -1738,7 +1741,7 @@ export function superForm<
17381741
await applyAction({
17391742
type: 'failure',
17401743
status: Form_resultStatus(result.status),
1741-
data: { form }
1744+
data: result
17421745
});
17431746
}
17441747
}

src/routes/(v2)/v2/app-error/+page.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
console.log(e.result);
1313
// @ts-expect-error Does not follow the App.Error shape
1414
error = 'code' in e.result.error ? e.result.error.code : e.result.error.message;
15-
}
15+
},
16+
taintedMessage: false
1617
});
1718
1819
const { enhance, form } = spForm;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
const { form, errors, message, enhance, submit, submitting } = superForm(
1414
defaults({ email: '[email protected]', name: 'aaa' }, zod(schema)),
1515
{
16-
onError({ result, form }) {
16+
onError({ result }) {
1717
console.log('=== onError ===');
1818
19-
form.message = JSON.stringify(result.error, null, 2);
19+
$message = JSON.stringify(result.error, null, 2);
2020
2121
// Cast the error, as its type isn't unknown.
2222
const error = result.error as unknown as {
@@ -25,7 +25,7 @@
2525
} & Record<string, unknown>;
2626
2727
if (!defaultStatus) result.status = error.status;
28-
form.errors = error.errors;
28+
$errors = error.errors;
2929
},
3030
async onUpdate({ form, result }) {
3131
console.log('=== onUpdate ===');
@@ -90,7 +90,7 @@
9090
<br />
9191
<input type="checkbox" bind:checked={shouldThrowIfNotSuccess} /> Throw if not success
9292
<br />
93-
<input type="checkbox" bind:checked={defaultStatus} /> Status 500 on error
93+
<input type="checkbox" bind:checked={defaultStatus} /> Status 400 on error
9494
</div>
9595

9696
{#if $message}

0 commit comments

Comments
 (0)