Skip to content

Automatically reset form with use:enhance #7163

@hanszoons

Description

@hanszoons

Describe the bug

Without an argument, use:enhance will emulate the browser-native behaviour, just without the full-page reloads.

Native browser behaviour clears form inputs after submit (or rather the associated page reload does that).

The progressively enhanced forms do not. This would require resetting the form in the enhance callback. This works:

<form
	method="post"
	action="?/doSomething"
	use:enhance={({ form }) => {
		return async ({ update }) => {
			form.reset();
			await update();
		};
	}}
>

But is still a hassle.

Reproduction

This applies to all SvelteKit installs.

Logs

No response

System Info

System:
    OS: macOS 12.6
    CPU: (10) arm64 Apple M1 Pro
    Memory: 7.58 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.9.0 - ~/.nvm/versions/node/v18.9.0/bin/node
    npm: 8.19.1 - ~/.nvm/versions/node/v18.9.0/bin/npm
  Browsers:
    Chrome: 105.0.5195.125
    Firefox: 105.0.1
    Safari: 16.0
  npmPackages:
    @sveltejs/adapter-auto: ^1.0.0-next.76 => 1.0.0-next.80 
    @sveltejs/adapter-node: ^1.0.0-next.96 => 1.0.0-next.96 
    @sveltejs/adapter-vercel: ^1.0.0-next.77 => 1.0.0-next.77 
    @sveltejs/kit: ^1.0.0-next.489 => 1.0.0-next.507 
    svelte: ^3.50.1 => 3.50.1 
    vite: ^3.1.4 => 3.1.4

Severity

annoyance

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingformsStuff relating to forms and form actionsp2-nice-to-haveSvelteKit cannot be used by a small number of people, quality of life improvements, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions