batch form is not submitted with XHR when it's a global action
This commit is contained in:
parent
2f884df602
commit
c65cc26be8
|
@ -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()
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -283,15 +283,18 @@
|
|||
|
||||
{% if configuration.hasBatchAction(context) %}
|
||||
<div class="mb-2">
|
||||
<form class="form-inline" action="{{ path(configuration.pageRoute('batch'), {page: pager.currentPageNumber}|merge(configuration.pageRouteParams('batch'))) }}" id="form-batch" method="POST">
|
||||
<form class="form-inline" action="{{ path(configuration.pageRoute('batch'), {
|
||||
page: pager.currentPageNumber,
|
||||
redirectTo: app.request.uri
|
||||
}|merge(configuration.pageRouteParams('batch'))) }}" id="form-batch" method="POST">
|
||||
<select class="form-control my-1 mr-sm-2" name="batch[target]">
|
||||
<option value="selection">{{ 'For selection'|trans }}</option>
|
||||
<option value="all">{{ 'For all items'|trans }}</option>
|
||||
</select>
|
||||
<select class="form-control my-1 mr-sm-2" name="batch[action]">
|
||||
<select class="form-control my-1 mr-sm-2" id="form-batch-action" name="batch[action]">
|
||||
<option value=""></option>
|
||||
{% for action, conf in configuration.batchActions(context) %}
|
||||
<option value="{{ action }}">
|
||||
<option value="{{ action }}" {% if conf.isGlobal %}data-isglobal="true"{% endif %}>
|
||||
{{ conf.label|trans }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
|
|
Loading…
Reference in a new issue