fix(partial): form dialog method not supported (#2927)
The `<form>` method value `dialog` does no network request, so we should ignore it for partials. Fixes https://github.com/denoland/fresh/issues/2885
This commit is contained in:
@@ -219,10 +219,7 @@ document.addEventListener("submit", async (e) => {
|
|||||||
const lowerMethod =
|
const lowerMethod =
|
||||||
e.submitter?.getAttribute("formmethod")?.toLowerCase() ??
|
e.submitter?.getAttribute("formmethod")?.toLowerCase() ??
|
||||||
el.method.toLowerCase();
|
el.method.toLowerCase();
|
||||||
if (
|
if (lowerMethod !== "get" && lowerMethod !== "post") {
|
||||||
lowerMethod !== "get" && lowerMethod !== "post" &&
|
|
||||||
lowerMethod !== "dialog"
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1833,6 +1833,45 @@ Deno.test({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "partials - submit form dialog should do nothing",
|
||||||
|
fn: async () => {
|
||||||
|
const app = testApp()
|
||||||
|
.post("/partial", () => {
|
||||||
|
throw new Error("FAIL");
|
||||||
|
})
|
||||||
|
.get("/", (ctx) => {
|
||||||
|
return ctx.render(
|
||||||
|
<Doc>
|
||||||
|
<div f-client-nav>
|
||||||
|
<dialog open>
|
||||||
|
<p>Greetings, one and all!</p>
|
||||||
|
<form method="dialog">
|
||||||
|
<Partial name="foo">
|
||||||
|
<p class="init">init</p>
|
||||||
|
</Partial>
|
||||||
|
<SelfCounter />
|
||||||
|
<button type="submit" class="update">OK</button>
|
||||||
|
</form>
|
||||||
|
</dialog>
|
||||||
|
</div>
|
||||||
|
</Doc>,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
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(".update").click();
|
||||||
|
await page.locator("dialog:not([open])").wait();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "partials - submit form redirect",
|
name: "partials - submit form redirect",
|
||||||
fn: async () => {
|
fn: async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user