Add simple flag to prevent multiple submits for Order Form AJAX

This commit is contained in:
Lance Edgar 2017-04-18 18:43:14 -05:00
parent 589a747662
commit ee2137e1bf

View file

@ -7,6 +7,9 @@
${parent.extra_javascript()} ${parent.extra_javascript()}
${h.javascript_link(request.static_url('tailbone:static/js/numeric.js'))} ${h.javascript_link(request.static_url('tailbone:static/js/numeric.js'))}
<script type="text/javascript"> <script type="text/javascript">
var submitting = false;
$(function() { $(function() {
$('.order-form td.current-order input').keydown(function(event) { $('.order-form td.current-order input').keydown(function(event) {
@ -14,21 +17,25 @@
return true; return true;
} }
if (event.which == 13) { if (event.which == 13) {
var row = $(this).parents('tr:first'); if (! submitting) {
var form = $('#item-update-form'); submitting = true;
form.find('[name="product_uuid"]').val(row.data('uuid')); var row = $(this).parents('tr:first');
form.find('[name="cases_ordered"]').val(row.find('input[name^="cases_ordered_"]').val() || '0'); var form = $('#item-update-form');
form.find('[name="units_ordered"]').val(row.find('input[name^="units_ordered_"]').val() || '0'); form.find('[name="product_uuid"]').val(row.data('uuid'));
$.post(form.attr('action'), form.serialize(), function(data) { form.find('[name="cases_ordered"]').val(row.find('input[name^="cases_ordered_"]').val() || '0');
if (data.error) { form.find('[name="units_ordered"]').val(row.find('input[name^="units_ordered_"]').val() || '0');
alert(data.error); $.post(form.attr('action'), form.serialize(), function(data) {
} else { if (data.error) {
row.find('input[name^="cases_ordered_"]').val(data.row_cases_ordered); alert(data.error);
row.find('input[name^="units_ordered_"]').val(data.row_units_ordered); } else {
row.find('td.po-total').html(data.row_po_total); row.find('input[name^="cases_ordered_"]').val(data.row_cases_ordered);
$('.po-total .field').html(data.batch_po_total); row.find('input[name^="units_ordered_"]').val(data.row_units_ordered);
} row.find('td.po-total').html(data.row_po_total);
}); $('.po-total .field').html(data.batch_po_total);
}
submitting = false;
});
}
} }
return false; return false;
}); });