Skip to content

Commit d257d37

Browse files
authored
feat: expose submitter in SubmitFunction (#9425)
closes #9414
1 parent 4409502 commit d257d37

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

Diff for: .changeset/lemon-mayflies-design.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': minor
3+
---
4+
5+
feat: expose submitter in use:enhance SubmitFunction

Diff for: documentation/docs/20-core-concepts/30-form-actions.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,12 @@ To customise the behaviour, you can provide a `SubmitFunction` that runs immedia
344344
```svelte
345345
<form
346346
method="POST"
347-
use:enhance={({ form, data, action, cancel }) => {
347+
use:enhance={({ form, data, action, cancel, submitter }) => {
348348
// `form` is the `<form>` element
349349
// `data` is its `FormData` object
350350
// `action` is the URL to which the form is posted
351351
// `cancel()` will prevent the submission
352+
// `submitter` is the `HTMLElement` that caused the form to be submitted
352353
353354
return async ({ result, update }) => {
354355
// `result` is an `ActionResult` object

Diff for: packages/kit/src/runtime/app/forms.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ export function enhance(form, submit = () => {}) {
9191
cancel,
9292
controller,
9393
data,
94-
form
94+
form,
95+
submitter: event.submitter
9596
})) ?? fallback_callback;
9697
if (cancelled) return;
9798

Diff for: packages/kit/types/ambient.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ declare module '$app/forms' {
8484
form: HTMLFormElement;
8585
controller: AbortController;
8686
cancel(): void;
87+
submitter: HTMLElement | null;
8788
}) => MaybePromise<
8889
| void
8990
| ((opts: {

0 commit comments

Comments
 (0)