From c65cc26be8f130cc0b191558cff4e4f6091933c6 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 12 Oct 2023 15:27:36 +0200 Subject: [PATCH] batch form is not submitted with XHR when it's a global action --- src/core/Resources/assets/js/modules/batch.js | 28 +++++++++++++------ .../views/admin/crud/index.html.twig | 9 ++++-- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/core/Resources/assets/js/modules/batch.js b/src/core/Resources/assets/js/modules/batch.js index 2d5c1f2..9e11c9f 100644 --- a/src/core/Resources/assets/js/modules/batch.js +++ b/src/core/Resources/assets/js/modules/batch.js @@ -8,16 +8,28 @@ module.exports = () => { const form = $('#form-batch') form.submit((e) => { - e.preventDefault() + const select = document.querySelector('#form-batch-action') + const options = select.querySelectorAll('#form-batch-action option') + let doPrevent = true - const route = form.attr('action') - const datas = form.serialize() + options.forEach((option) => { + if (option.value === select.value && option.getAttribute('data-isglobal') === 'true') { + doPrevent = false + } + }) - form.addClass('is-loading') + if (doPrevent) { + e.preventDefault() - $.post(route, datas) - .always(() => { - document.location.reload() - }) + const route = form.attr('action') + const datas = form.serialize() + + form.addClass('is-loading') + + $.post(route, datas) + .always(() => { + document.location.reload() + }) + } }) } diff --git a/src/core/Resources/views/admin/crud/index.html.twig b/src/core/Resources/views/admin/crud/index.html.twig index cdf4cc0..d8e17f9 100644 --- a/src/core/Resources/views/admin/crud/index.html.twig +++ b/src/core/Resources/views/admin/crud/index.html.twig @@ -283,15 +283,18 @@ {% if configuration.hasBatchAction(context) %}
-
+ - {% for action, conf in configuration.batchActions(context) %} - {% endfor %}