Skip to content

Add clear and reset methods to RemoteForm instances#1

Open
thomasmol wants to merge 2 commits into
mainfrom
feat/add-clear-and-reset-to-form-remote-function
Open

Add clear and reset methods to RemoteForm instances#1
thomasmol wants to merge 2 commits into
mainfrom
feat/add-clear-and-reset-to-form-remote-function

Conversation

@thomasmol

Copy link
Copy Markdown
Owner

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.

@thomasmol thomasmol requested a review from Copilot August 14, 2025 08:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds clear() and reset() methods to RemoteForm instances, providing developers with programmatic ways to clear form results and reset form fields. The changes enable better form state management for remote forms in SvelteKit applications.

  • Adds clear() method to clear the form result (set to undefined)
  • Adds reset() method to reset form fields using the native HTML form reset functionality
  • Implements server-side no-op versions of these methods for SSR compatibility

Reviewed Changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated 1 comment.

File Description
packages/kit/src/runtime/client/remote-functions/form.svelte.js Implements client-side clear() and reset() methods with form reference tracking
packages/kit/src/runtime/app/server/remote/form.js Adds server-side no-op implementations of clear() and reset() methods
packages/kit/test/apps/basics/src/routes/remote/form/+page.svelte Adds test buttons to verify the new clear() and reset() functionality

* Reset the current form fields using its built-in reset() method
*/
function reset() {
if (current_form && current_form instanceof HTMLFormElement) {

Copilot AI Aug 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The instanceof check is redundant since current_form is already typed as HTMLFormElement | null and is only assigned HTMLFormElement values. The check can be simplified to just if (current_form).

Suggested change
if (current_form && current_form instanceof HTMLFormElement) {
if (current_form) {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants