From 79f8fae92819b6076969a67372e6e17e06da876d Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 28 Oct 2021 23:43:38 +0200 Subject: [PATCH 3/5] js: delay submit until autosave ajax request is finished (#58276) --- wcs/qommon/static/js/qommon.forms.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/wcs/qommon/static/js/qommon.forms.js b/wcs/qommon/static/js/qommon.forms.js index 6168efb9..56cf790a 100644 --- a/wcs/qommon/static/js/qommon.forms.js +++ b/wcs/qommon/static/js/qommon.forms.js @@ -124,6 +124,8 @@ Responsive_table_widget.prototype.init = function () { $(function() { var autosave_timeout_id = null; var autosave_is_running = false; + var autosave_button_to_click_on_complete = null; + if ($('form[data-has-draft]:not([data-autosave=false])').length == 1) { var last_auto_save = $('form[data-has-draft]').serialize(); function autosave() { @@ -149,6 +151,9 @@ $(function() { if (autosave_timeout_id !== null) { install_autosave(); } + if (autosave_button_to_click_on_complete !== null) { + autosave_button_to_click_on_complete.click(); + } } }); } @@ -391,6 +396,14 @@ $(function() { } return true; }); + $('form .buttons.submit button').on('click', function (event) { + if (autosave_is_running) { + autosave_button_to_click_on_complete = event.target; + /* prevent more autosave */ + autosave_timeout_id = null; + event.preventDefault(); + } + }); $('form').on('submit', function(event) { var $form = $(this); /* prevent more autosave */ -- 2.33.0