Skip to content

Commit

Permalink
Guard against non-numeric data in Javascript. Issue #73.
Browse files Browse the repository at this point in the history
  • Loading branch information
lcreid committed Mar 7, 2017
1 parent a58b47d commit ac90712
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/cf0925s.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $(document).on('turbolinks:load', function() {
// console.log('Updating the item total: ' + $('#cf0925_item_total').val());
$('#cf0925_item_total').val($(item_ids).toArray().reduce(function(a, b) {
// console.log('a, b: ', + a + ', ' + b.value);
return b.value === undefined? a: a + Number(b.value);
return $.isNumeric(b.value)? a + Number(b.value.replace(/[,$]/g, "")): a;
}, 0).toFixed(2));
// console.log('Updated the item total: ' + $('#cf0925_item_total').val());
};
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/invoices.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ $(document).on('turbolinks:load', function() {
function update_out_of_pocket() {
allocated_spending = allocation_fields().toArray().reduce(function(a, b) {
// console.log('update_out_of_pocket b: ' + b.value);
return b.value === undefined? a: a + Number(b.value.replace(/[,$]/g, ""));
return $.isNumeric(b.value)? a + Number(b.value.replace(/[,$]/g, "")): a;
}, 0);

// console.log('allocated_spending: ' + allocated_spending);
Expand Down

0 comments on commit ac90712

Please sign in to comment.