From c3a5d92a1fd4903cfab4b33ad08f6d955ab62935 Mon Sep 17 00:00:00 2001 From: Kenny DiFiore Date: Mon, 6 Mar 2017 11:12:08 -0500 Subject: [PATCH 1/3] 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. --- src/global/percentage/percentage.js | 2 +- src/global/percentage/percentage.test.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/global/percentage/percentage.js b/src/global/percentage/percentage.js index a98f7ec1..d1e3ebed 100644 --- a/src/global/percentage/percentage.js +++ b/src/global/percentage/percentage.js @@ -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) { diff --git a/src/global/percentage/percentage.test.js b/src/global/percentage/percentage.test.js index 255f711e..9b65aada 100644 --- a/src/global/percentage/percentage.test.js +++ b/src/global/percentage/percentage.test.js @@ -64,6 +64,21 @@ describe('ui-percentage-mask', function() { expect(model.$viewValue).toBe('100%'); }); + it('should hide space before "%" if ui-hide-space is present and model value is changed', function() { + var input = TestUtil.compile('', { + model: 1, + decimals: 0 + }); + + var model = input.controller('ngModel'); + expect(model.$viewValue).toBe('100%'); + + $rootScope.model = 0.5; + $rootScope.digest(); + + expect(model.$viewValue).toBe('50%'); + }); + it('should allow changing the number of decimals', angular.mock.inject(function($rootScope) { var input = TestUtil.compile('', { model: '12.345', From 19474c67908c45feea0ac05de847ae55781d5137 Mon Sep 17 00:00:00 2001 From: Kenny DiFiore Date: Mon, 6 Mar 2017 11:17:47 -0500 Subject: [PATCH 2/3] 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. --- src/global/percentage/percentage.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/global/percentage/percentage.test.js b/src/global/percentage/percentage.test.js index 9b65aada..93430aa3 100644 --- a/src/global/percentage/percentage.test.js +++ b/src/global/percentage/percentage.test.js @@ -64,7 +64,7 @@ describe('ui-percentage-mask', function() { expect(model.$viewValue).toBe('100%'); }); - it('should hide space before "%" if ui-hide-space is present and model value is changed', function() { + it('should hide space before "%" if ui-hide-space is present and model value is changed', function($rootScope) { var input = TestUtil.compile('', { model: 1, decimals: 0 From 7f7fc3c7986effd134065018ffe25947eecb437f Mon Sep 17 00:00:00 2001 From: Kenny DiFiore Date: Mon, 6 Mar 2017 11:17:47 -0500 Subject: [PATCH 3/3] 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. --- src/global/percentage/percentage.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/global/percentage/percentage.test.js b/src/global/percentage/percentage.test.js index 9b65aada..9aabebbf 100644 --- a/src/global/percentage/percentage.test.js +++ b/src/global/percentage/percentage.test.js @@ -64,7 +64,7 @@ describe('ui-percentage-mask', function() { expect(model.$viewValue).toBe('100%'); }); - it('should hide space before "%" if ui-hide-space is present and model value is changed', function() { + it('should hide space before "%" if ui-hide-space is present and model value is changed', function($rootScope) { var input = TestUtil.compile('', { model: 1, decimals: 0 @@ -74,7 +74,7 @@ describe('ui-percentage-mask', function() { expect(model.$viewValue).toBe('100%'); $rootScope.model = 0.5; - $rootScope.digest(); + $rootScope.$digest(); expect(model.$viewValue).toBe('50%'); });