Make partials support any http method :3

This commit is contained in:
2026-11-11 16:27:12 -03:00
parent 0e6aa1d232
commit 8400c019e0
4 changed files with 289 additions and 8 deletions
+13 -7
View File
@@ -262,14 +262,17 @@ document.addEventListener("submit", async (e) => {
return;
}
const lowerMethod =
e.submitter?.getAttribute("formmethod")?.toLowerCase() ??
el.method.toLowerCase();
if (lowerMethod !== "get" && lowerMethod !== "post") {
const method = e.submitter?.getAttribute("formmethod")?.toLowerCase() ||
el.getAttribute("method")?.toLowerCase() || "get";
if (method === "dialog") {
return;
}
const hasExplicitPartial = e.submitter?.hasAttribute(PARTIAL_ATTR) ||
const isCustomMethod = method !== "get" && method !== "post";
const hasExplicitPartial = isCustomMethod ||
e.submitter?.hasAttribute(PARTIAL_ATTR) ||
e.submitter?.hasAttribute("formaction") ||
el.hasAttribute(PARTIAL_ATTR) ||
el.hasAttribute("action");
@@ -300,13 +303,16 @@ document.addEventListener("submit", async (e) => {
let init: RequestInit | undefined;
// GET method appends form data via url search params
if (lowerMethod === "get") {
if (method === "get") {
// 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.append(key, value));
} else {
init = { body: new FormData(el, e.submitter), method: lowerMethod };
init = {
body: new FormData(el, e.submitter),
method: method?.toUpperCase(),
};
}
try {