diff --git a/static/src/app.js b/static/src/app.js index da39d7d..eac43a4 100644 --- a/static/src/app.js +++ b/static/src/app.js @@ -9,6 +9,10 @@ // Forms answer validation errors with 422; HTMX must swap those too so errors are shown. if (window.htmx) { + // Settle right after the swap. HTMX wires hx-* attributes of new content (such as a dialog + // form's hx-post) only when it settles; with the default 20 ms delay a quick Enter in that + // gap submitted the form as a normal page load and focus was lost. + window.htmx.config.defaultSettleDelay = 0; window.htmx.config.responseHandling = [ { code: "204", swap: false }, { code: "[23]..", swap: true }, diff --git a/tests/browser/test_customers.py b/tests/browser/test_customers.py index d1cbdf7..204626f 100644 --- a/tests/browser/test_customers.py +++ b/tests/browser/test_customers.py @@ -64,7 +64,7 @@ def test_add_contact_with_keyboard( page.locator("#item-dialog button[type=submit]").focus() page.keyboard.press("Enter") page.wait_for_selector("#id_name[aria-invalid='true']") - # Focus moves in htmx:afterSettle, a moment after the swap. + # Focus moves in htmx:afterSettle. page.wait_for_function("document.activeElement && document.activeElement.id === 'id_name'") page.keyboard.type("Pekka Puhelin")