Skip to content

Conversation

@sillvva
Copy link
Contributor

@sillvva sillvva commented Oct 21, 2025

fixes #14754
fixes #14210
fixes #14787

Implements a form.reset() method that clears the form values, issues, result, submitted, and touched states. In addition, the dev is provided options to not reset certain parts, and the ability to reset the form to new values.

Includes SSR support, so the dev could also use form.reset({ values: { ... } }) in the script block instead of form.fields.set({ ... }) if they wanted to. One advantage is that it allows a DeepPartial<Input> type, instead of requiring the whole object. Unlike .set() this method is only for the base path.

Demo

export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
	...
	/** Reset the form to its initial state */
	reset(options?: {
		/**
		 * Set this to the new values to reset the form to.
		 * Set this to `false` to not reset the values.
		 * @default true
		 */
		values?: DeepPartial<Input> | boolean;
		/** Set this to `false` to not reset the issues. */
		issues?: boolean;
		/** Set this to `false` to not reset the result. */
		result?: boolean;
		/** Set this to `false` to not reset the touched fields. */
		touched?: boolean;
	}): void;
};

It does provide an alternative solution to this issue too:

When navigating to a new page and back on the client, the values (input), issues, and result are not reset. Looking into this, I see that the instance is only deleted on submit if the form has a key from .for(key). This PR would give developers the ability to reset without using .for().


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot
Copy link

changeset-bot bot commented Oct 21, 2025

🦋 Changeset detected

Latest commit: 8423853

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svelte-docs-bot
Copy link

@sillvva sillvva changed the title Form reset Reset form programmatically Oct 21, 2025
@sillvva sillvva changed the title Reset form programmatically feat: Reset form programmatically Oct 21, 2025
@sillvva sillvva mentioned this pull request Oct 26, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant