Skip to content
Snippets Groups Projects
Commit 588a5c52 authored by Markus Timtner's avatar Markus Timtner Committed by Jan Helke
Browse files

[BUGFIX] Fix doubleclick-doublesubmit touchup

If a user double-clicks fast enough on any save-button of any new record
in Chrome, the record gets submitted twice.
This fix introduces a semaphore variable in the corresponding JS
to ensure the record gets submitted only once.

Resolves: #77942
Related: #77729, #77944
Releases: master, 7.6
Change-Id: I73516b6a07b23b947e0756dea7051863546a246d
Reviewed-on: https://review.typo3.org/50720


Reviewed-by: default avatarMarkus Klein <markus.klein@typo3.org>
Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Tested-by: default avatarGianluigi Martino <gmartino27@gmail.com>
Reviewed-by: default avatarGianluigi Martino <gmartino27@gmail.com>
Reviewed-by: default avatarJan Helke <typo3@helke.de>
Tested-by: default avatarJan Helke <typo3@helke.de>
parent cb077ae2
Branches
Tags
No related merge requests found
...@@ -31,6 +31,7 @@ define(['jquery', 'TYPO3/CMS/Backend/Icons'], function($, Icons) { ...@@ -31,6 +31,7 @@ define(['jquery', 'TYPO3/CMS/Backend/Icons'], function($, Icons) {
* Initializes the save handling * Initializes the save handling
*/ */
SplitButtons.initializeSaveHandling = function() { SplitButtons.initializeSaveHandling = function() {
var preventExec = false;
var elements = [ var elements = [
'button[form]', 'button[form]',
'button[name^="_save"]', 'button[name^="_save"]',
...@@ -39,45 +40,49 @@ define(['jquery', 'TYPO3/CMS/Backend/Icons'], function($, Icons) { ...@@ -39,45 +40,49 @@ define(['jquery', 'TYPO3/CMS/Backend/Icons'], function($, Icons) {
'a[data-name="CMD"][data-value^="save"]' 'a[data-name="CMD"][data-value^="save"]'
].join(','); ].join(',');
$('.t3js-module-docheader').on('click', elements, function(e) { $('.t3js-module-docheader').on('click', elements, function(e) {
var $me = $(this), // prevent doubleclick double submission bug in chrome,
linkedForm = $me.attr('form') || $me.attr('data-form') || null, // see https://forge.typo3.org/issues/77942
$form = linkedForm ? $('#' + linkedForm) : $me.closest('form'), if (!preventExec) {
name = $me.data('name') || this.name, preventExec = true;
value = $me.data('value') || this.value, var $me = $(this),
$elem = $('<input />').attr('type', 'hidden').attr('name', name).attr('value', value); linkedForm = $me.attr('form') || $me.attr('data-form') || null,
$form = linkedForm ? $('#' + linkedForm) : $me.closest('form'),
name = $me.data('name') || this.name,
value = $me.data('value') || this.value,
$elem = $('<input />').attr('type', 'hidden').attr('name', name).attr('value', value);
// Run any preSubmit callbacks // Run any preSubmit callbacks
for (var i = 0; i < SplitButtons.preSubmitCallbacks.length; ++i) { for (var i = 0; i < SplitButtons.preSubmitCallbacks.length; ++i) {
SplitButtons.preSubmitCallbacks[i](e); SplitButtons.preSubmitCallbacks[i](e);
}
$form.append($elem);
// Disable submit buttons
$form.on('submit', function() {
if ($form.find('.has-error').length > 0) {
return false;
} }
$form.append($elem);
// Disable submit buttons
$form.on('submit', function() {
if ($form.find('.has-error').length > 0) {
preventExec = false;
return false;
}
var $affectedButton, var $affectedButton,
$splitButton = $me.closest('.t3js-splitbutton'); $splitButton = $me.closest('.t3js-splitbutton');
if ($splitButton.length > 0) { if ($splitButton.length > 0) {
$splitButton.find('button').prop('disabled', true); $splitButton.find('button').prop('disabled', true);
$affectedButton = $splitButton.children().first(); $affectedButton = $splitButton.children().first();
} else { } else {
$me.prop('disabled', true); $me.prop('disabled', true);
$affectedButton = $me; $affectedButton = $me;
} }
Icons.getIcon('spinner-circle-dark', Icons.sizes.small).done(function(markup) { Icons.getIcon('spinner-circle-dark', Icons.sizes.small).done(function(markup) {
$affectedButton.find('.t3js-icon').replaceWith(markup); $affectedButton.find('.t3js-icon').replaceWith(markup);
});
}); });
});
if ((e.currentTarget.tagName === 'A' || $me.attr('form')) && !e.isDefaultPrevented()) { if ((e.currentTarget.tagName === 'A' || $me.attr('form')) && !e.isDefaultPrevented()) {
$form.submit(); $form.submit();
e.preventDefault(); e.preventDefault();
}
} }
}); });
}; };
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment