Skip to content

Textfield is empty after form submit with use:enhance #9609

@Beiri22

Description

@Beiri22

Describe the bug

I am using a form to save some string into the db. When the form loads, the load function supplies the old string from db. After sending the form (with use:enhance) the textarea is empty.

What else:
-> without use:enhance it works as intended
-> the variable holds the correct content
-> an input type=text showed the same behaviour

Reproduction

<script lang="ts">
	import { enhance } from '$app/forms';

	export let data;
	let content = "";

	// When setting content directly, each keystroke triggers the content setting. You cannot type. This way, the reactive
	// statement does not know about content and thus only triggers with prop change.
	function setContent(s:string)
	{
		content = s
	}

	$: setContent(data.report?.content || '');
</script>

<form method="POST" use:enhance>
    <textarea name="content" cols="100" rows="20" bind:value={content} />
    <button type="submit">Absenden</button>
</form>

{JSON.stringify(data.report)} <- shows correct version of saved report

{content} <- is also updated correctly

Logs

No response

System Info

System:
    OS: Linux 6.2 Manjaro Linux
    CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
    Memory: 22.83 GB / 31.27 GB
    Container: Yes
    Shell: 3.6.0 - /usr/bin/fish
  Binaries:
    Node: 19.8.1 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 8.19.2 - /usr/bin/npm
  Browsers:
    Chromium: 111.0.5563.110
    Firefox: 111.0.1
  npmPackages:
    @sveltejs/adapter-node: ^1.0.0 => 1.2.3 
    @sveltejs/kit: ^1.0.0 => 1.15.1 
    svelte: ^3.54.0 => 3.58.0 
    vite: ^4.0.0 => 4.2.1

Severity

serious, but I can work around it

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingformsStuff relating to forms and form actionsp3-edge-caseSvelteKit cannot be used in an uncommon wayready to implementplease submit PRs for these issues!

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions