Skip to content

Commit

Permalink
feat(ui-money-mask): allow decimals as strings
Browse files Browse the repository at this point in the history
* allows decimals as string at MoneyMask

* add tests that covers strings as definition of decimals at MoneyMask

* removing unnecessary code

* moving tests to the correct place
  • Loading branch information
marcomafessolli authored and assisrafael committed Apr 27, 2016
1 parent 23dc640 commit 34fea60
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/global/money/money.js
Expand Up @@ -26,7 +26,7 @@ function MoneyMaskDirective($locale, $parse, PreFormatters) {
if (isNaN(decimals)) {
decimals = 2;
}

decimals = parseInt(decimals);
var moneyMask = maskFactory(decimals);

function formatter(value) {
Expand Down Expand Up @@ -73,6 +73,7 @@ function MoneyMaskDirective($locale, $parse, PreFormatters) {
if (attrs.uiMoneyMask) {
scope.$watch(attrs.uiMoneyMask, function(_decimals) {
decimals = isNaN(_decimals) ? 2 : _decimals;
decimals = parseInt(decimals);
moneyMask = maskFactory(decimals);

parser(ctrl.$viewValue);
Expand Down
13 changes: 13 additions & 0 deletions src/global/money/money.test.js
Expand Up @@ -67,6 +67,19 @@ describe('ui-money-mask', function() {
expect(model.$viewValue).toBe('$ 3,456.79');
}));

it('shold allow string as definition of decimals', angular.mock.inject(function($rootScope) {
var input = TestUtil.compile('<input ng-model="model" ui-money-mask="decimals">', {
model: '3456.79',
decimals: "2"
});

var model = input.controller('ngModel');
expect(model.$viewValue).toBe('$ 3,456.79');
$rootScope.decimals = "3";
$rootScope.$digest();
expect(model.$viewValue).toBe('$ 345.679');
}));

it('should validate minimum value', function() {
var input = TestUtil.compile('<input ng-model="model" ui-money-mask min="50">', {
model: '3456.79'
Expand Down

0 comments on commit 34fea60

Please sign in to comment.