Skip to content

Commit 34fea60

Browse files
marcomafessolliassisrafael
authored andcommitted
feat(ui-money-mask): allow decimals as strings
* 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
1 parent 23dc640 commit 34fea60

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/global/money/money.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function MoneyMaskDirective($locale, $parse, PreFormatters) {
2626
if (isNaN(decimals)) {
2727
decimals = 2;
2828
}
29-
29+
decimals = parseInt(decimals);
3030
var moneyMask = maskFactory(decimals);
3131

3232
function formatter(value) {
@@ -73,6 +73,7 @@ function MoneyMaskDirective($locale, $parse, PreFormatters) {
7373
if (attrs.uiMoneyMask) {
7474
scope.$watch(attrs.uiMoneyMask, function(_decimals) {
7575
decimals = isNaN(_decimals) ? 2 : _decimals;
76+
decimals = parseInt(decimals);
7677
moneyMask = maskFactory(decimals);
7778

7879
parser(ctrl.$viewValue);

src/global/money/money.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ describe('ui-money-mask', function() {
6767
expect(model.$viewValue).toBe('$ 3,456.79');
6868
}));
6969

70+
it('shold allow string as definition of decimals', angular.mock.inject(function($rootScope) {
71+
var input = TestUtil.compile('<input ng-model="model" ui-money-mask="decimals">', {
72+
model: '3456.79',
73+
decimals: "2"
74+
});
75+
76+
var model = input.controller('ngModel');
77+
expect(model.$viewValue).toBe('$ 3,456.79');
78+
$rootScope.decimals = "3";
79+
$rootScope.$digest();
80+
expect(model.$viewValue).toBe('$ 345.679');
81+
}));
82+
7083
it('should validate minimum value', function() {
7184
var input = TestUtil.compile('<input ng-model="model" ui-money-mask min="50">', {
7285
model: '3456.79'

0 commit comments

Comments
 (0)