fix: accept response code 422 in htmx as 'should swap'

This commit is contained in:
Björn Fromme
2026-05-28 15:02:53 +02:00
parent 5561a24050
commit 97f88d5eeb
+9
View File
@@ -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
}
})