Add simple flag to prevent multiple submits for Order Form AJAX
This commit is contained in:
parent
589a747662
commit
ee2137e1bf
|
@ -7,6 +7,9 @@
|
|||
${parent.extra_javascript()}
|
||||
${h.javascript_link(request.static_url('tailbone:static/js/numeric.js'))}
|
||||
<script type="text/javascript">
|
||||
|
||||
var submitting = false;
|
||||
|
||||
$(function() {
|
||||
|
||||
$('.order-form td.current-order input').keydown(function(event) {
|
||||
|
@ -14,21 +17,25 @@
|
|||
return true;
|
||||
}
|
||||
if (event.which == 13) {
|
||||
var row = $(this).parents('tr:first');
|
||||
var form = $('#item-update-form');
|
||||
form.find('[name="product_uuid"]').val(row.data('uuid'));
|
||||
form.find('[name="cases_ordered"]').val(row.find('input[name^="cases_ordered_"]').val() || '0');
|
||||
form.find('[name="units_ordered"]').val(row.find('input[name^="units_ordered_"]').val() || '0');
|
||||
$.post(form.attr('action'), form.serialize(), function(data) {
|
||||
if (data.error) {
|
||||
alert(data.error);
|
||||
} else {
|
||||
row.find('input[name^="cases_ordered_"]').val(data.row_cases_ordered);
|
||||
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);
|
||||
}
|
||||
});
|
||||
if (! submitting) {
|
||||
submitting = true;
|
||||
var row = $(this).parents('tr:first');
|
||||
var form = $('#item-update-form');
|
||||
form.find('[name="product_uuid"]').val(row.data('uuid'));
|
||||
form.find('[name="cases_ordered"]').val(row.find('input[name^="cases_ordered_"]').val() || '0');
|
||||
form.find('[name="units_ordered"]').val(row.find('input[name^="units_ordered_"]').val() || '0');
|
||||
$.post(form.attr('action'), form.serialize(), function(data) {
|
||||
if (data.error) {
|
||||
alert(data.error);
|
||||
} else {
|
||||
row.find('input[name^="cases_ordered_"]').val(data.row_cases_ordered);
|
||||
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;
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue