Add clear and reset methods to RemoteForm instances#1
Open
thomasmol wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits