From 79a262b344322a11fc201415d97696d9e08436cd Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Tue, 2 Jul 2024 22:24:48 +0200 Subject: [PATCH] fix: GET partial form submit ignoring multiple checkbox values (#2568) Fixes https://github.com/denoland/fresh/issues/2567 --- src/runtime/client/partials.ts | 2 +- tests/partials_test.tsx | 58 ++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/runtime/client/partials.ts b/src/runtime/client/partials.ts index ef3557cd..f4add4c9 100644 --- a/src/runtime/client/partials.ts +++ b/src/runtime/client/partials.ts @@ -252,7 +252,7 @@ document.addEventListener("submit", async (e) => { // TODO: Looks like constructor type for URLSearchParam is wrong // deno-lint-ignore no-explicit-any const qs = new URLSearchParams(new FormData(el, e.submitter) as any); - qs.forEach((value, key) => partialUrl.searchParams.set(key, value)); + qs.forEach((value, key) => partialUrl.searchParams.append(key, value)); } else { init = { body: new FormData(el, e.submitter), method: lowerMethod }; } diff --git a/tests/partials_test.tsx b/tests/partials_test.tsx index 2de6b95d..7dfc15e8 100644 --- a/tests/partials_test.tsx +++ b/tests/partials_test.tsx @@ -1784,6 +1784,64 @@ Deno.test({ }, }); +Deno.test({ + name: "partials - form submit multiple values", + fn: async () => { + const app = testApp() + .get("/partial", (ctx) => { + const values = ctx.url.searchParams.getAll("name"); + return ctx.render( + + +

done

+
+
, + ); + }) + .get("/", (ctx) => { + return ctx.render( + +
+
+ + + + +

init

+
+ + + +
+
, + ); + }); + + await withBrowserApp(app, async (page, address) => { + await page.goto(address, { waitUntil: "load" }); + await page.locator(".ready").wait(); + + await page.locator(".increment").click(); + await waitForText(page, ".output", "1"); + + await page.locator("input[value=a]").evaluate((el) => + el.checked = true + ); + await page.locator("input[value=b]").evaluate((el) => + el.checked = true + ); + await page.locator("input[value=c]").evaluate((el) => + el.checked = true + ); + + await page.locator(".update").click(); + await page.locator(".done-a-b-c").wait(); + }); + }, +}); + Deno.test({ name: "partials - fragment nav should not cause infinite loop", fn: async () => {