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')
|
const form = $('#form-batch')
|
||||||
|
|
||||||
form.submit((e) => {
|
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')
|
options.forEach((option) => {
|
||||||
const datas = form.serialize()
|
if (option.value === select.value && option.getAttribute('data-isglobal') === 'true') {
|
||||||
|
doPrevent = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
form.addClass('is-loading')
|
if (doPrevent) {
|
||||||
|
e.preventDefault()
|
||||||
|
|
||||||
$.post(route, datas)
|
const route = form.attr('action')
|
||||||
.always(() => {
|
const datas = form.serialize()
|
||||||
document.location.reload()
|
|
||||||
})
|
form.addClass('is-loading')
|
||||||
|
|
||||||
|
$.post(route, datas)
|
||||||
|
.always(() => {
|
||||||
|
document.location.reload()
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,15 +283,18 @@
|
||||||
|
|
||||||
{% if configuration.hasBatchAction(context) %}
|
{% if configuration.hasBatchAction(context) %}
|
||||||
<div class="mb-2">
|
<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]">
|
<select class="form-control my-1 mr-sm-2" name="batch[target]">
|
||||||
<option value="selection">{{ 'For selection'|trans }}</option>
|
<option value="selection">{{ 'For selection'|trans }}</option>
|
||||||
<option value="all">{{ 'For all items'|trans }}</option>
|
<option value="all">{{ 'For all items'|trans }}</option>
|
||||||
</select>
|
</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>
|
<option value=""></option>
|
||||||
{% for action, conf in configuration.batchActions(context) %}
|
{% for action, conf in configuration.batchActions(context) %}
|
||||||
<option value="{{ action }}">
|
<option value="{{ action }}" {% if conf.isGlobal %}data-isglobal="true"{% endif %}>
|
||||||
{{ conf.label|trans }}
|
{{ conf.label|trans }}
|
||||||
</option>
|
</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
Loading…
Reference in a new issue