Dispatch event on CSRF form field value change (#1376)

This allow support / compatibility with LiveComponent when action are done between form first render and submit 

(ex: another form submit with Turbo and double header check)

See https://github.com/symfony/ux/issues/2505
This commit is contained in:
Simon André
2025-01-20 08:44:45 +01:00
committed by GitHub
parent a98652006b
commit 84862d352c
@@ -15,6 +15,7 @@ document.addEventListener('submit', function (event) {
if (!csrfCookie && nameCheck.test(csrfToken)) {
csrfField.setAttribute('data-csrf-protection-cookie-value', csrfCookie = csrfToken);
csrfField.defaultValue = csrfToken = btoa(String.fromCharCode.apply(null, (window.crypto || window.msCrypto).getRandomValues(new Uint8Array(18))));
csrfField.dispatchEvent(new Event('change', {bubbles: true}));
}
if (csrfCookie && tokenCheck.test(csrfToken)) {