Fix for javascript failures when partial dollars are used for campaign amounts

This commit is contained in:
Eric Schultz 2018-03-28 15:56:45 -05:00
parent e0cb5a4880
commit b91f878584
2 changed files with 5 additions and 1 deletions

View file

@ -17,6 +17,10 @@ format.camelToWords = function(str, os) {
format.dollarsToCents = function(dollars) { format.dollarsToCents = function(dollars) {
dollars = dollars.toString().replace(/[$,]/g, '') dollars = dollars.toString().replace(/[$,]/g, '')
if(!isNaN(dollars) && dollars.match(/^-?\d+\.\d$/)) {
// could we use toFixed instead? Probably but this is straightforward.
dollars = dollars + "0"
}
if(isNaN(dollars) || !dollars.match(/^-?\d+(\.\d\d)?$/)) throw "Invalid dollar amount: " + dollars if(isNaN(dollars) || !dollars.match(/^-?\d+(\.\d\d)?$/)) throw "Invalid dollar amount: " + dollars
return Math.round(Number(dollars) * 100) return Math.round(Number(dollars) * 100)
} }

View file

@ -187,7 +187,7 @@ function showSingleAmount(isRecurring, state) {
var desig = state.params$().designation var desig = state.params$().designation
return h('section.u-centered', [ return h('section.u-centered', [
h('p.singleAmount-message', [ h('p.singleAmount-message', [
h('strong', app.currency_symbol + state.params$().single_amount) h('strong', app.currency_symbol + format.centsToDollars(format.dollarsToCents(state.params$().single_amount)))
, h('span.u-padding--0', { class: {'u-hide': !isRecurring} }, ' monthly') , h('span.u-padding--0', { class: {'u-hide': !isRecurring} }, ' monthly')
, h('span', {class: {'u-hide': !state.params$().designation && !gift.id}}, [ ' for ' + (desig || gift.name) ]) , h('span', {class: {'u-hide': !state.params$().designation && !gift.id}}, [ ' for ' + (desig || gift.name) ])
]) ])