1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 12:12:48 +01:00

Prevent duplicat submissions

This commit is contained in:
Hillel Coren 2018-02-21 15:36:00 +02:00
parent b6ba6fccda
commit de2bcc92cf
6 changed files with 29 additions and 16 deletions

View File

@ -1465,9 +1465,10 @@
}
@if (Auth::user()->canCreateOrEdit(ENTITY_INVOICE, $invoice))
if ($('#saveButton').is(':disabled')) {
return false;
}
if (NINJA.formIsSubmitted) {
return false;
}
NINJA.formIsSubmitted = true;
$('#saveButton, #emailButton, #draftButton').attr('disabled', true);
// if save fails ensure user can try again
$.post('{{ url($url) }}', $('.main-form').serialize(), function(data) {
@ -1489,6 +1490,7 @@
function handleSaveFailed(data) {
$('#saveButton, #emailButton, #draftButton').attr('disabled', false);
$('#emailModal div.modal-footer button').attr('disabled', false);
NINJA.formIsSubmitted = false;
var error = '';
if (data) {
var error = firstJSONError(data.responseJSON) || data.statusText;

View File

@ -36,6 +36,8 @@
},
onError: function(e) {
$form.find('button').prop('disabled', false);
NINJA.formIsSubmitted = false;
// Show the errors on the form
if (e.details && e.details.invalidFieldKeys.length) {
var invalidField = e.details.invalidFieldKeys[0];

View File

@ -227,6 +227,10 @@
var amount = $('#amount').val();
if (NINJA.parseFloat(amount) <= invoice.balance || confirm("{{ trans('texts.amount_greater_than_balance') }}")) {
if (NINJA.formIsSubmitted) {
return false;
}
NINJA.formIsSubmitted = true;
$('#saveButton').attr('disabled', true);
return true;
} else {

View File

@ -14,11 +14,6 @@
}
event.preventDefault();
if (NINJA.formIsSubmitted) {
return false;
}
NINJA.formIsSubmitted = true;
var $form = $(this);
var data = {
@ -52,6 +47,11 @@
return false;
}
if (NINJA.formIsSubmitted) {
return false;
}
NINJA.formIsSubmitted = true;
// Disable the submit button to prevent repeated clicks
$form.find('button').prop('disabled', true);
$('#js-error-message').hide();
@ -98,6 +98,7 @@
error = "{{trans('texts.country_not_supported')}}";
}
$form.find('button').prop('disabled', false);
NINJA.formIsSubmitted = false;
$('#js-error-message').html(error).fadeIn();
} else {
// response contains id and card, which contains additional card details

View File

@ -10,10 +10,6 @@
$(function() {
$('.payment-form').unbind('submit').submit(function(event) {
event.preventDefault();
if (NINJA.formIsSubmitted) {
return false;
}
NINJA.formIsSubmitted = true;
if ($('[name=plaidAccountId]').length) {
return;
@ -53,6 +49,11 @@
}
}
if (NINJA.formIsSubmitted) {
return false;
}
NINJA.formIsSubmitted = true;
// Disable the submit button to prevent repeated clicks
$form.find('button').prop('disabled', true);
$('#js-error-message').hide();
@ -72,6 +73,7 @@
// Show the errors on the form
var error = response.error.message;
$form.find('button').prop('disabled', false);
NINJA.formIsSubmitted = false;
$('#js-error-message').html(error).fadeIn();
} else {
// response contains id and card, which contains additional card details

View File

@ -12,10 +12,6 @@
var $form = $('.payment-form');
$('.payment-form').submit(function(event) {
event.preventDefault();
if (NINJA.formIsSubmitted) {
return false;
}
NINJA.formIsSubmitted = true;
var data = {
client_id: {{ WEPAY_CLIENT_ID }},
@ -49,8 +45,13 @@
// Show the errors on the form
var error = response.error_description;
$form.find('button').prop('disabled', false);
NINJA.formIsSubmitted = false;
$('#js-error-message').text(error).fadeIn();
} else {
if (NINJA.formIsSubmitted) {
return false;
}
NINJA.formIsSubmitted = true;
// response contains id and card, which contains additional card details
var token = response.credit_card_id;
// Insert the token into the form so it gets submitted to the server
@ -64,6 +65,7 @@
// Show the errors on the form
var error = response.error_description;
$form.find('button').prop('disabled', false);
NINJA.formIsSubmitted = false;
$('#js-error-message').text(error).fadeIn();
}