Skip to content

Commit

Permalink
Merge pull request #129 from legalthings/price_fields_should_be_store…
Browse files Browse the repository at this point in the history
…d_as_float_comma_fix

Use parseNumber for formatting price field
  • Loading branch information
svenstm committed Jan 22, 2019
2 parents afa2c67 + 3ff2e39 commit f3fc083
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 21 deletions.
2 changes: 0 additions & 2 deletions js/legalform-calc.js
Expand Up @@ -55,8 +55,6 @@ function LegalFormCalc($) {

if (type === 'group' && field.multiple) {
value = typeof(value) !== 'undefined' ? [value] : [];
} else if (type === 'money' && value) {
value = parseFloat(value);
}

addGroupedData(data, step.group, field.name, value);
Expand Down
19 changes: 0 additions & 19 deletions js/ractive-legalform.js
Expand Up @@ -137,8 +137,6 @@

if (isComputed) return;


this.onChangeMoney(newValue, oldValue, keypath);
this.onChangeAmount(newValue, oldValue, keypath);

var isEmpty = newValue === null ||
Expand Down Expand Up @@ -216,23 +214,6 @@
}, 10);
},

/**
* Cast money to float
* @param {string} newValue
* @param {string} oldValue
* @param {string} keypath
*/
onChangeMoney: function(newValue, oldValue, keypath) {
var meta = this.get('meta.' + keypath);
var isMoney = typeof meta !== 'undefined' &&
typeof meta.type !== 'undefined' &&
meta.type === 'money';

if (isMoney && newValue) {
this.set(keypath, parseFloat(newValue));
}
},

/**
* Handle change of amount options from singular to plural, and backwords.
* @param {mixed} newValue
Expand Down
Expand Up @@ -10,6 +10,7 @@ describe("test parseNumber function", function() {
{number: 134, expected: 134.0, note: '134 should be converted to 134.0'},
{number: 1.34, expected: 1.34, note: '1.34 should be converted to 1.34'},
{number: '1,34', expected: 1.34, note: '1,34 should be converted to 1.34'},
{number: '1,30', expected: 1.3, note: '1,30 should be converted to 1.3, thus not preserving ending zero'},
{number: '12,503,348.09', expected: 12503348.09, note: '12,503,348.09 should be converted to 12503348.09'},
{number: '12.503.348,09', expected: 12503348.09, note: '12.503.348,09 should be converted to 12503348.09'},
{number: '12503348.09', expected: 12503348.09, note: '12503348.09 should be converted to 12503348.09'},
Expand Down

0 comments on commit f3fc083

Please sign in to comment.