mirror of
https://github.com/symfony/recipes.git
synced 2026-09-20 19:46:52 +03:00
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:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user