From 49fc98bac8e8de24d5d1db9a64770aa39c884761 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 28 Oct 2021 18:25:32 +0200 Subject: [PATCH 2/4] js: abort current autosave ajax request on submit (#58276) --- wcs/qommon/static/js/qommon.forms.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/wcs/qommon/static/js/qommon.forms.js b/wcs/qommon/static/js/qommon.forms.js index 4a5a89e2..219c0d87 100644 --- a/wcs/qommon/static/js/qommon.forms.js +++ b/wcs/qommon/static/js/qommon.forms.js @@ -124,6 +124,7 @@ Responsive_table_widget.prototype.init = function () { $(function() { var autosave_timeout_id = null; var autosave_is_running = false; + var autosave_xhr = null; if ($('form[data-has-draft]').length == 1) { var last_auto_save = $('form[data-has-draft]').serialize(); function autosave() { @@ -135,7 +136,7 @@ $(function() { install_autosave(); return; } - $.ajax({ + autosave_xhr = $.ajax({ type: 'POST', url: window.location.pathname + 'autosave', data: new_auto_save, @@ -146,6 +147,7 @@ $(function() { }, complete: function() { autosave_is_running = false; + autosave_xhr = null; if (autosave_timeout_id !== null) { install_autosave(); } @@ -379,6 +381,11 @@ $(function() { }); $('form').on('submit', function(event) { var $form = $(this); + /* abort current autosave */ + if (autosave_xhr !== null) { + autosave_xhr.abort(); + autosave_xhr = null; + } /* prevent more autosave */ if (autosave_timeout_id !== null) { window.clearTimeout(autosave_timeout_id); -- 2.33.0