From d80d8210f9ec53787a1b7e9e599d26e29381a10b Mon Sep 17 00:00:00 2001 From: montana Date: Tue, 18 Jun 2019 14:57:38 -0400 Subject: [PATCH] Handle NaN in obligated amount input properly - there is some hackiness to the text input portion --- js/components/text_input.js | 3 ++- js/components/totals_box.js | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/js/components/text_input.js b/js/components/text_input.js index 4c22b6c4..dd20ea09 100644 --- a/js/components/text_input.js +++ b/js/components/text_input.js @@ -103,7 +103,8 @@ export default { this.value = e.target.value.trim() if (this.validation === 'dollars') { - this.value = formatDollars(this._rawValue(e.target.value)) + let value = Number.isNaN(e.target.value) ? '0' : e.target.value + this.value = formatDollars(this._rawValue(value)) } }, diff --git a/js/components/totals_box.js b/js/components/totals_box.js index 6bc64c40..8ce5fb49 100644 --- a/js/components/totals_box.js +++ b/js/components/totals_box.js @@ -11,10 +11,16 @@ export default { computed: { formattedObligated: function() { - return formatDollars(this.obligated) + return formatDollars(this._filterNaN(this.obligated)) }, formattedContractAmount: function() { - return formatDollars(this.contractAmount) + return formatDollars(this._filterNaN(this.contractAmount)) + }, + }, + + methods: { + _filterNaN: function(value) { + return Number.isNaN(value) ? 0 : value }, }, }