From 181387ca6d762408353a49a3effb3bf87317b540 Mon Sep 17 00:00:00 2001 From: Adam LeVasseur Date: Wed, 11 Sep 2013 01:37:50 -0400 Subject: [PATCH 1/2] Avoiding double-submit issues in change_form with a bit of JS --- suit/static/suit/js/suit.js | 17 +++++++++++++++++ suit/templates/admin/change_form.html | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/suit/static/suit/js/suit.js b/suit/static/suit/js/suit.js index 43289657..ccbc4342 100644 --- a/suit/static/suit/js/suit.js +++ b/suit/static/suit/js/suit.js @@ -160,6 +160,23 @@ activate_tabs(); }; + /** + * Avoids double-submit issues in the change_form. + */ + $.fn.suit_form_debounce = function() { + var $form = $(this), + $saveButtons = $form.find('.save-box button'), + submitting = false; + + $form.submit(function() { + if (submitting) { + return false; + } + + submitting = true; + $saveButtons.attr('disabled', true); + }); + }; $(function () { diff --git a/suit/templates/admin/change_form.html b/suit/templates/admin/change_form.html index c86c0da6..21131265 100644 --- a/suit/templates/admin/change_form.html +++ b/suit/templates/admin/change_form.html @@ -31,6 +31,14 @@ }(Suit.$)) {% endif %} + + {% endblock %} From 903f6b794fb51ca4a6358cc09a667981fa95c2fb Mon Sep 17 00:00:00 2001 From: Adam LeVasseur Date: Fri, 13 Sep 2013 12:56:03 -0400 Subject: [PATCH 2/2] [double-submit issue] using CSS class to disable buttons since the form relies on the button field value for logic --- suit/static/suit/js/suit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/suit/static/suit/js/suit.js b/suit/static/suit/js/suit.js index ccbc4342..d19cda0d 100644 --- a/suit/static/suit/js/suit.js +++ b/suit/static/suit/js/suit.js @@ -174,7 +174,7 @@ } submitting = true; - $saveButtons.attr('disabled', true); + $saveButtons.addClass('disabled'); }); };