Skip to content

Commit

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

Cast money to float
  • Loading branch information
svenstm authored Dec 6, 2018
2 parents cb2b590 + 56f3d79 commit ee774b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions js/legalform-calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ 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: 19 additions & 0 deletions js/ractive-legalform.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@

if (isComputed) return;


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

var isEmpty = newValue === null ||
Expand Down Expand Up @@ -209,6 +211,23 @@
}, 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

0 comments on commit ee774b2

Please sign in to comment.