Fixes for double-submit on butons

- Function that first unbinds the submit button
This commit is contained in:
Oliver 2018-05-08 22:49:23 +10:00
parent bf4ffb8b0b
commit fdf35bd741
2 changed files with 12 additions and 6 deletions

View File

@ -65,6 +65,15 @@ function closeModal(modal='#modal-form') {
$(modal).modal('hide'); $(modal).modal('hide');
} }
function modalSubmit(modal, callback) {
$(modal).off('click', '#modal-form-submit');
$(modal).on('click', '#modal-form-submit', function() {
callback();
});
}
function openModal(options) { function openModal(options) {
var modal = options.modal || '#modal-form'; var modal = options.modal || '#modal-form';
@ -188,10 +197,7 @@ function handleModalForm(url, options) {
return false; return false;
}); });
// Un-bind any attached click listeners modalSubmit(modal, function() {
$(modal).off('click', '#modal-form-submit');
$(modal).on('click', '#modal-form-submit', function() {
$(modal).find('.js-modal-form').ajaxSubmit({ $(modal).find('.js-modal-form').ajaxSubmit({
url: url, url: url,
// POST was successful // POST was successful

View File

@ -102,7 +102,7 @@ function updateStock(items, options={}) {
content: html content: html
}); });
$(modal).on('click', '#modal-form-submit', function() { modalSubmit(modal, function() {
var stocktake = []; var stocktake = [];
@ -244,7 +244,7 @@ function moveStockItems(items, options) {
modalSetContent(modal, html); modalSetContent(modal, html);
attachSelect(modal); attachSelect(modal);
$(modal).on('click', '#modal-form-submit', function() { modalSubmit(modal, function() {
var locId = $(modal).find("#stock-location").val(); var locId = $(modal).find("#stock-location").val();
doMove(locId, parts); doMove(locId, parts);