Skip to content

fix: inject false for unchecked boolean checkboxes in remote form submission#15786

Closed
PranavAgarkar07 wants to merge 1 commit intosveltejs:mainfrom
PranavAgarkar07:fix/unchecked-checkbox-remote-form
Closed

fix: inject false for unchecked boolean checkboxes in remote form submission#15786
PranavAgarkar07 wants to merge 1 commit intosveltejs:mainfrom
PranavAgarkar07:fix/unchecked-checkbox-remote-form

Conversation

@PranavAgarkar07
Copy link
Copy Markdown

Fixes #15785.

In SvelteKit 2.59.0, unchecked checkboxes using z.coerce.boolean() failed to submit because the client-side form submission logic didn't account for b:-prefixed fields missing from FormData.

This PR adds a get_form_data helper in form.svelte.js that injects 'false' into the FormData for any b:-prefixed input that is absent from the FormData (i.e. unchecked checkboxes).

A regression test has been added to packages/kit/test/apps/async to verify that unchecked checkboxes submit successfully.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 2, 2026

🦋 Changeset detected

Latest commit: 39e3570

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 Patch

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

Comment thread packages/kit/src/runtime/client/remote-functions/form.svelte.js Outdated
@PranavAgarkar07 PranavAgarkar07 force-pushed the fix/unchecked-checkbox-remote-form branch from 08e2d70 to d1edd02 Compare May 2, 2026 12:13
@PranavAgarkar07
Copy link
Copy Markdown
Author

Good catch, applied. Thanks!

@PranavAgarkar07 PranavAgarkar07 force-pushed the fix/unchecked-checkbox-remote-form branch from d1edd02 to 39e3570 Compare May 2, 2026 12:19
@ottomated
Copy link
Copy Markdown
Contributor

Unfortunately this can't work because it introduces a difference in behavior between enhanced and non-enhanced forms. If there's no JavaScript, the false value won't be injected.

event.preventDefault();

const form_data = new FormData(form, event.submitter);
const form_data = get_form_data(form, event.submitter);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ottomated is right. We probably need to account for undefined checked values on the server rather than modifying the data on the client so that it works without JS on the client

await expect(page.locator('#set-value-display')).toHaveText('Set via method');
});

test('unchecked checkbox submits successfully', async ({ page }) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should probably move this test to test.js so that it's tested without JS too

@PranavAgarkar07
Copy link
Copy Markdown
Author

Makes sense — preventing non-optional booleans at the schema level is the right fix since it works consistently with and without JS. Closing in favor of #15804. Thanks for the feedback @ottomated @teemingc!

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.59.0] Cannot submit form with unchecked checkbox

3 participants