Skip to content

Commit

Permalink
feat: expose submitter in SubmitFunction (#9425)
Browse files Browse the repository at this point in the history
closes #9414
  • Loading branch information
msonnberger authored Mar 15, 2023
1 parent 4409502 commit d257d37
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-mayflies-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': minor
---

feat: expose submitter in use:enhance SubmitFunction
3 changes: 2 additions & 1 deletion documentation/docs/20-core-concepts/30-form-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,12 @@ To customise the behaviour, you can provide a `SubmitFunction` that runs immedia
```svelte
<form
method="POST"
use:enhance={({ form, data, action, cancel }) => {
use:enhance={({ form, data, action, cancel, submitter }) => {
// `form` is the `<form>` element
// `data` is its `FormData` object
// `action` is the URL to which the form is posted
// `cancel()` will prevent the submission
// `submitter` is the `HTMLElement` that caused the form to be submitted
return async ({ result, update }) => {
// `result` is an `ActionResult` object
Expand Down
3 changes: 2 additions & 1 deletion packages/kit/src/runtime/app/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export function enhance(form, submit = () => {}) {
cancel,
controller,
data,
form
form,
submitter: event.submitter
})) ?? fallback_callback;
if (cancelled) return;

Expand Down
1 change: 1 addition & 0 deletions packages/kit/types/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ declare module '$app/forms' {
form: HTMLFormElement;
controller: AbortController;
cancel(): void;
submitter: HTMLElement | null;
}) => MaybePromise<
| void
| ((opts: {
Expand Down

0 comments on commit d257d37

Please sign in to comment.