diff --git a/slhx-js/runtime/slhx.js b/slhx-js/runtime/slhx.js index eb4129a..e36e7c5 100644 --- a/slhx-js/runtime/slhx.js +++ b/slhx-js/runtime/slhx.js @@ -27,10 +27,15 @@ function formOwner(el) { if (!el || el.tagName === "FORM") return el; - if (el.getAttribute && el.getAttribute("form")) return document.getElementById(el.getAttribute("form")); + if (el.getAttribute && el.getAttribute("form")) return elementById(rootOf(el) || document, el.getAttribute("form")); return closestInRoot(el, rootOf(el) || document, (node) => node.tagName === "FORM"); } + function elementById(scope, id) { + if (attrEquals(scope, "id", id)) return scope; + return firstElement(scope, (el) => attrEquals(el, "id", id)); + } + function formHandleId(form) { if (!form) return null; const holder = form.hasAttribute(HID) ? form : firstElement(form, (el) => el.hasAttribute(HID)); diff --git a/slhx-js/tests/runtime.rs b/slhx-js/tests/runtime.rs index 8fc0550..bfb1ce4 100644 --- a/slhx-js/tests/runtime.rs +++ b/slhx-js/tests/runtime.rs @@ -94,12 +94,14 @@ fn runtime_handles_get_forms_without_request_body() { #[test] fn runtime_clicking_submitter_schedules_form_submit() { - // req: convention/004 + // req: convention/004 req: runtime/001 let source = slhx_js::RUNTIME_JS; assert!(source.contains("function formOwner(el)")); assert!(source.contains("function formHandleId(form)")); - assert!(source.contains("document.getElementById(el.getAttribute(\"form\"))")); + assert!(source.contains("function elementById(scope, id)")); + assert!(source.contains("return elementById(rootOf(el) || document, el.getAttribute(\"form\"))")); + assert!(!source.contains("document.getElementById(el.getAttribute(\"form\"))")); assert!(source.contains("const direct = closestInRoot(event.target, root, (el) => el.hasAttribute(HID))")); assert!(source.contains("const submitter = closestInRoot(event.target, root, (el) =>")); assert!(source.contains("el.tagName === \"BUTTON\" && (!el.hasAttribute(\"type\") || el.getAttribute(\"type\") === \"submit\")"));