Files
natascha-rieter-nl/user/plugins/form/templates/forms/layouts/xhr.html.twig
T
2026-04-18 23:38:26 +02:00

25 lines
1.6 KiB
Twig

{% if form.xhr_submit == true %}
{# Ensure xhr-submitter.js is loaded BEFORE the inline JS that uses it #}
{% do assets.addJs('plugin://form/assets/xhr-submitter.js', {'group': 'bottom', 'priority': 101, 'position': 'before'}) %}
{% do assets.addInlineJs("
document.addEventListener('DOMContentLoaded', () => {
// This now primarily sets up the *potential* for XHR submission
// It might not attach the listener directly if recaptcha is present
attachFormSubmitListener('" ~ form.id ~ "');
// Re-run captcha initializers *if* the form was loaded via XHR initially
// This covers edge cases, might not be strictly needed if captcha script handles DOMContentLoaded
const formElement = document.getElementById('" ~ form.id ~ "');
if (formElement && window.GravRecaptchaInitializers) {
const initializerFuncName = 'initRecaptcha_" ~ form.id ~ "';
if (typeof window.GravRecaptchaInitializers[initializerFuncName] === 'function') {
// Check if it needs init (e.g., if container exists but no widget/listener)
// For simplicity, just call it again; the init function should be idempotent
// window.GravRecaptchaInitializers[initializerFuncName]();
}
}
});",
{'group': 'bottom', 'priority': 100, 'position': 'before'}) %}
{% do assets.addJs('plugin://form/assets/captcha/recaptcha-handler.js', {'group': 'bottom', 'priority': 99, 'position': 'before'}) %}
{% do assets.addJs('plugin://form/assets/captcha/turnstile-handler.js', {'group': 'bottom', 'priority': 98, 'position': 'before'}) %}
{% endif %}