Skip to content

Commit

Permalink
Merge e43347a into 8204c83
Browse files Browse the repository at this point in the history
  • Loading branch information
gmq committed Jul 6, 2016
2 parents 8204c83 + e43347a commit 4f0c05e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/global/money/money.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ function MoneyMaskDirective($locale, $parse, PreFormatters) {
link: function(scope, element, attrs, ctrl) {
var decimalDelimiter = $locale.NUMBER_FORMATS.DECIMAL_SEP,
thousandsDelimiter = $locale.NUMBER_FORMATS.GROUP_SEP,
currencySym = $locale.NUMBER_FORMATS.CURRENCY_SYM,
currencySym = (typeof (attrs.currencySymbol) !== 'undefined') ? attrs.currencySymbol : $locale.NUMBER_FORMATS.CURRENCY_SYM,
decimals = $parse(attrs.uiMoneyMask)(scope);

function maskFactory(decimals) {
var decimalsPattern = decimals > 0 ? decimalDelimiter + new Array(decimals + 1).join('0') : '';
var maskPattern = currencySym + ' #' + thousandsDelimiter + '##0' + decimalsPattern;
var currencySymbolPattern = (currencySym) ? currencySym + ' #' : '#';
var maskPattern = currencySymbolPattern + thousandsDelimiter + '##0' + decimalsPattern;
return new StringMask(maskPattern, {reverse: true});
}

Expand Down
18 changes: 18 additions & 0 deletions src/global/money/money.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,22 @@ describe('ui-money-mask', function() {
expect(model.$viewValue).toBe('$ 0.00');
expect(model.$modelValue).toBe(0);
});

it('should change currency symbol if defined', function() {
var input = TestUtil.compile('<input ng-model="model" ui-money-mask currency-symbol="F$">', {
model: 345.00
});

var model = input.controller('ngModel');
expect(model.$viewValue).toBe('F$ 345.00');
});

it('should remove space if currency symbol is defined but empty', function() {
var input = TestUtil.compile('<input ng-model="model" ui-money-mask currency-symbol="">', {
model: 345.00
});

var model = input.controller('ngModel');
expect(model.$viewValue).toBe('345.00');
});
});

0 comments on commit 4f0c05e

Please sign in to comment.