From 97f88d5eeb21fde001d7c6d6930e7d12391dc241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Wed, 20 May 2026 14:55:41 +0200 Subject: [PATCH] fix: accept response code 422 in htmx as 'should swap' --- assets/app.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/assets/app.js b/assets/app.js index 6ced00b..36c5a9f 100644 --- a/assets/app.js +++ b/assets/app.js @@ -13,3 +13,12 @@ htmx.config.allowScriptTags = false htmx.config.withCredentials = true htmx.config.selfRequestsOnly = false htmx.config.timeout = 50000 // 50 seconds - slightly higher than backend timeout (45s) + +document.body.addEventListener('htmx:beforeSwap', (event) => { + // Symfony renders invalid forms with 422; let HTMX swap those responses so inline + // validation errors are actually shown to the user. + if (event.detail?.xhr?.status === 422) { + event.detail.shouldSwap = true + event.detail.isError = false + } +})