From 61f3701d14ac0576594f5b17414bcfd6cb0ac459 Mon Sep 17 00:00:00 2001 From: mokaddem Date: Tue, 23 Mar 2021 10:04:06 +0100 Subject: [PATCH] fix: [genericTemplates:indexFilter] Correct usage of confirmFunction --- templates/genericTemplates/filters.php | 7 +++---- webroot/js/bootstrap-helper.js | 29 ++++++++++++++------------ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/templates/genericTemplates/filters.php b/templates/genericTemplates/filters.php index 1e28173..b3b0c91 100644 --- a/templates/genericTemplates/filters.php +++ b/templates/genericTemplates/filters.php @@ -30,7 +30,7 @@ echo $this->Bootstrap->modal([ 'type' => 'confirm', 'bodyHtml' => $filteringForm, 'confirmText' => __('Filter'), - 'confirmFunction' => 'filterIndex(clicked)' + 'confirmFunction' => 'filterIndex' ]); ?> @@ -40,11 +40,10 @@ echo $this->Bootstrap->modal([ initFilteringTable($filteringTable) }) - function filterIndex(clicked) { + function filterIndex(modalObject, tmpApi) { const controller = 'request->getParam('controller') ?>'; const action = 'index'; - const $clicked = $(clicked) - const $tbody = $clicked.closest('div.modal-content').find('table.indexFilteringTable tbody') + const $tbody = modalObject.$modal.find('table.indexFilteringTable tbody') const $rows = $tbody.find('tr:not(#controlRow)') const activeFilters = {} $rows.each(function() { diff --git a/webroot/js/bootstrap-helper.js b/webroot/js/bootstrap-helper.js index 2922694..8cb39e3 100644 --- a/webroot/js/bootstrap-helper.js +++ b/webroot/js/bootstrap-helper.js @@ -704,19 +704,22 @@ class ModalFactory { if ($submitButton.data('confirmfunction') !== undefined && $submitButton.data('confirmfunction') !== '') { const clickHandler = window[$submitButton.data('confirmfunction')] this.options.APIConfirm = (tmpApi) => { - return clickHandler(this, tmpApi) - .then((data) => { - if (data.success) { - this.options.POSTSuccessCallback(data) - } else { // Validation error - this.injectFormValidationFeedback(form, data.errors) - return Promise.reject('Validation error'); - } - }) - .catch((errorMessage) => { - this.options.POSTFailCallback(errorMessage) - return Promise.reject(errorMessage); - }) + let clickResult = clickHandler(this, tmpApi) + if (clickResult !== undefined) { + return clickResult + .then((data) => { + if (data.success) { + this.options.POSTSuccessCallback(data) + } else { // Validation error + this.injectFormValidationFeedback(form, data.errors) + return Promise.reject('Validation error'); + } + }) + .catch((errorMessage) => { + this.options.POSTFailCallback(errorMessage) + return Promise.reject(errorMessage); + }) + } } } else { $submitButton[0].removeAttribute('onclick')