Skip to content
Discussion options

You must be logged in to vote

You can use form.requestSubmit():

<script>
	let form;
</script>

<form bind:this={form}>
	<input
		type="text"
		name="search"
		on:change={() => form.requestSubmit()}
	/>
</form>

In contrast with form.submit() which only submits the form, this will trigger everything (validation, submit event handling, etc) that would happen if a user clicked the 'Submit' button.

Though note that by default SvelteKit will reset browser focus, which can be disruptive if you're submitting the form on each change. If you don't want that, see #7895 for workarounds.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by dummdidumm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #8498 on January 13, 2023 08:45.