From fdf35bd741870d5f15bba6b6f8d3c5a8a1bc74b6 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 8 May 2018 22:49:23 +1000 Subject: [PATCH] Fixes for double-submit on butons - Function that first unbinds the submit button --- InvenTree/static/script/inventree/modals.js | 14 ++++++++++---- InvenTree/static/script/inventree/stock.js | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/InvenTree/static/script/inventree/modals.js b/InvenTree/static/script/inventree/modals.js index 562ad67413..f29ed0919b 100644 --- a/InvenTree/static/script/inventree/modals.js +++ b/InvenTree/static/script/inventree/modals.js @@ -65,6 +65,15 @@ function closeModal(modal='#modal-form') { $(modal).modal('hide'); } +function modalSubmit(modal, callback) { + $(modal).off('click', '#modal-form-submit'); + + $(modal).on('click', '#modal-form-submit', function() { + callback(); + }); +} + + function openModal(options) { var modal = options.modal || '#modal-form'; @@ -188,10 +197,7 @@ function handleModalForm(url, options) { return false; }); - // Un-bind any attached click listeners - $(modal).off('click', '#modal-form-submit'); - - $(modal).on('click', '#modal-form-submit', function() { + modalSubmit(modal, function() { $(modal).find('.js-modal-form').ajaxSubmit({ url: url, // POST was successful diff --git a/InvenTree/static/script/inventree/stock.js b/InvenTree/static/script/inventree/stock.js index d984f075b6..cfcb8a84da 100644 --- a/InvenTree/static/script/inventree/stock.js +++ b/InvenTree/static/script/inventree/stock.js @@ -102,7 +102,7 @@ function updateStock(items, options={}) { content: html }); - $(modal).on('click', '#modal-form-submit', function() { + modalSubmit(modal, function() { var stocktake = []; @@ -244,7 +244,7 @@ function moveStockItems(items, options) { modalSetContent(modal, html); attachSelect(modal); - $(modal).on('click', '#modal-form-submit', function() { + modalSubmit(modal, function() { var locId = $(modal).find("#stock-location").val(); doMove(locId, parts);