fix(control-plane): bridge whynot-design forms into native submission
wn-input/wn-select/wn-button aren't form-associated custom elements — their real <input>/<select>/<button> live inside shadow DOM, invisible to an ancestor <form>. Clicking Sign In (or any wn-button[type=submit]) silently did nothing, and even a submitted form would have carried none of the field values. Bridges both gaps generically in base.html without touching the vendored library: mirrors each shadow-DOM control's live value into a hidden native input on submit, and explicitly calls form.requestSubmit() on wn-button[type=submit] clicks. Reported by the user clicking Sign In in the running local instance — missed by test_control_plane_app.py because TestClient POSTs directly and never exercises real button clicks or shadow DOM. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
87ccf37b59
commit
e103937e21
2 changed files with 58 additions and 0 deletions
|
|
@ -50,5 +50,47 @@
|
|||
Visual language vendored from <code>whynot-design</code> — see
|
||||
<code>static/whynot-design/VENDORED.md</code>.
|
||||
</p>
|
||||
|
||||
<script>
|
||||
// whynot-design's wn-input/wn-select/wn-textarea/wn-button are plain Lit
|
||||
// components, not form-associated custom elements — their real <input>/
|
||||
// <select>/<button> live inside shadow DOM, invisible to an ancestor
|
||||
// <form>. Without this, clicking a wn-button[type=submit] does nothing,
|
||||
// and even if it did, none of the field values would be part of the POST.
|
||||
// This bridges both gaps generically, for every .wn-form on every page,
|
||||
// without touching the vendored library itself.
|
||||
(function () {
|
||||
function readValue(el) {
|
||||
var native = el.shadowRoot && el.shadowRoot.querySelector("input, select, textarea");
|
||||
return native ? native.value : (el.value != null ? el.value : "");
|
||||
}
|
||||
|
||||
document.querySelectorAll("form").forEach(function (form) {
|
||||
form.addEventListener("submit", function () {
|
||||
form.querySelectorAll("[name]").forEach(function (el) {
|
||||
if (!el.tagName || el.tagName.indexOf("WN-") !== 0) return;
|
||||
var name = el.getAttribute("name");
|
||||
if (!name) return;
|
||||
var hidden = form.querySelector('input[type="hidden"][data-wn-mirror-for="' + name + '"]');
|
||||
if (!hidden) {
|
||||
hidden = document.createElement("input");
|
||||
hidden.type = "hidden";
|
||||
hidden.name = name;
|
||||
hidden.dataset.wnMirrorFor = name;
|
||||
form.appendChild(hidden);
|
||||
}
|
||||
hidden.value = readValue(el);
|
||||
});
|
||||
});
|
||||
|
||||
form.querySelectorAll("wn-button[type=submit]").forEach(function (btn) {
|
||||
btn.addEventListener("click", function () {
|
||||
if (typeof form.requestSubmit === "function") form.requestSubmit();
|
||||
else form.submit();
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -287,3 +287,19 @@ def test_audit_log_visible_to_signed_in_user(client, credentials):
|
|||
_login(client, credentials["viewer"].token)
|
||||
resp = client.get("/audit")
|
||||
assert resp.status_code == 200
|
||||
|
||||
|
||||
def test_form_bridge_script_present(client):
|
||||
"""whynot-design's wn-input/wn-select/wn-button are not
|
||||
form-associated custom elements — their real <input>/<select>/
|
||||
<button> live inside shadow DOM, invisible to an ancestor <form>. A
|
||||
plain click on wn-button[type=submit] silently does nothing, and
|
||||
even a submitted form would carry none of the field values. This
|
||||
only regressed once (base.html's bridging script), so pin its
|
||||
presence — TestClient can't click a real button/shadow DOM, this is
|
||||
the closest offline check available without a browser-automation
|
||||
tool."""
|
||||
resp = client.get("/login")
|
||||
assert "wn-button[type=submit]" in resp.text
|
||||
assert "requestSubmit" in resp.text
|
||||
assert "data-wn-mirror-for" in resp.text
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue