f-update-url

This commit is contained in:
2026-11-11 17:16:21 -03:00
parent 3866b47741
commit 8c552d05d1
3 changed files with 100 additions and 3 deletions
+63 -1
View File
@@ -2128,7 +2128,12 @@ Deno.test({
<Partial name="foo">
<p class="init">init</p>
</Partial>
<button type="submit" class="update" formmethod="DELETE">
<button
type="submit"
class="update"
formmethod="DELETE"
f-update-url="true"
>
delete
</button>
</form>
@@ -2150,6 +2155,63 @@ Deno.test({
},
});
Deno.test({
name: "partials - submit form f-update-url",
fn: async () => {
const app = testApp()
.delete("/items/1", renderMethodPartial)
.post("/partial", renderMethodPartial)
.get("/", (ctx) => {
return ctx.render(
<Doc>
<div f-client-nav>
<form>
<input name="name" value="foo" />
<Partial name="foo">
<p class="init">init</p>
</Partial>
<button
type="submit"
class="delete"
formaction="/items/1"
formmethod="DELETE"
>
delete
</button>
<button
type="submit"
class="post"
formaction="/partial"
formmethod="POST"
f-update-url="false"
>
post
</button>
</form>
</div>
</Doc>,
);
});
await withBrowserApp(app, async (page, address) => {
await page.goto(address, { waitUntil: "load" });
await page.locator(".init").wait();
// Custom methods leave the URL alone by default
await page.locator(".delete").click();
await page.locator(".done-DELETE-foo").wait();
let pathname = await page.evaluate(() => window.location.pathname);
expect(pathname).toEqual("/");
// f-update-url="false" opts POST out of updating the URL
await page.locator(".post").click();
await page.locator(".done-POST-foo").wait();
pathname = await page.evaluate(() => window.location.pathname);
expect(pathname).toEqual("/");
});
},
});
Deno.test({
name: "partials - submit form with formmethod HEAD is sent as GET",
fn: async () => {