Skip to content

Commit

Permalink
fix(uiPercentageMask): honor ui-hide-space when view value change to …
Browse files Browse the repository at this point in the history
…model update from controller (#260)

* fix(uiPercentageMask): honor ui-hide-space when view value change due to model update from controller

Previously, a change to the model in the controller would result in a space in between the percent sign and the value no matter if the ui-hide-space attribute is present or not.  Now, a change to the model will result in the correct view value format.

Non-breaking change.

* fix(uiPercentageMask): honor ui-hide-space when view value change due to model update from controller

Add missing mock inject in the new test.

Non-breaking change.

* fix(uiPercentageMask): honor ui-hide-space when view value change due to model update from controller

Update failing tests.  When accessing via rootScope, update model to 50 not 0.5 to represent 50%.

Non-breaking change.
  • Loading branch information
CareerFairPlus authored and assisrafael committed Apr 20, 2017
1 parent b04328d commit 3f51cad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/global/percentage/percentage.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function PercentageMaskDirective($locale, $parse, PreFormatters, NumberMasks) {
}

var valueToFormat = preparePercentageToFormatter(value, decimals, modelValue.multiplier);
return viewMask.apply(valueToFormat) + ' %';
return viewMask.apply(valueToFormat) + (hideSpace ? '%' : ' %');
}

function parse(value) {
Expand Down
14 changes: 14 additions & 0 deletions src/global/percentage/percentage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ describe('ui-percentage-mask', function() {
expect(model.$viewValue).toBe('100%');
});

it('should hide space before "%" after a model change if ui-hide-space is present', angular.mock.inject(function($rootScope) {
var input = TestUtil.compile('<input ng-model="model" ui-percentage-mask="decimals" ui-percentage-value ui-hide-space>', {
model: 1,
decimals: 0
});

var model = input.controller('ngModel');
expect(model.$viewValue).toBe('100%');

$rootScope.model = 50; // When accessing via rootScope, update model to 50 not 0.5 to represent 50%
$rootScope.$digest();
expect(model.$viewValue).toBe('50%');
}));

it('should allow changing the number of decimals', angular.mock.inject(function($rootScope) {
var input = TestUtil.compile('<input ng-model="model" ui-percentage-mask="decimals">', {
model: '12.345',
Expand Down

0 comments on commit 3f51cad

Please sign in to comment.