From ba9bdf7110821b43ca60c126b30b0dd54138bd48 Mon Sep 17 00:00:00 2001 From: Igor Rafael Date: Tue, 7 Apr 2015 09:17:44 -0300 Subject: [PATCH] fix(number): fix the result for 0 and other edge cases --- src/global/number/number.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/global/number/number.js b/src/global/number/number.js index be86ba31..a4fad3d4 100644 --- a/src/global/number/number.js +++ b/src/global/number/number.js @@ -25,8 +25,8 @@ angular.module('ui.utils.masks.global.number', [ var viewMask = NumberMasks.viewMask(decimals, decimalDelimiter, thousandsDelimiter), modelMask = NumberMasks.modelMask(decimals); - function parse(value) { - if(!value) { + function parser(value) { + if(ctrl.$isEmpty(value)) { return value; } @@ -54,21 +54,22 @@ angular.module('ui.utils.masks.global.number', [ return actualNumber; } - ctrl.$formatters.push(function(value) { + function formatter(value) { + if(ctrl.$isEmpty(value)) { + return value; + } + var prefix = ''; if(angular.isDefined(attrs.uiNegativeNumber) && value < 0){ prefix = '-'; } - if(!value) { - return value; - } - var valueToFormat = PreFormatters.prepareNumberToFormatter(value, decimals); return prefix + viewMask.apply(valueToFormat); - }); + } - ctrl.$parsers.push(parse); + ctrl.$formatters.push(formatter); + ctrl.$parsers.push(parser); if (attrs.uiNumberMask) { scope.$watch(attrs.uiNumberMask, function(decimals) { @@ -78,7 +79,7 @@ angular.module('ui.utils.masks.global.number', [ viewMask = NumberMasks.viewMask(decimals, decimalDelimiter, thousandsDelimiter); modelMask = NumberMasks.modelMask(decimals); - parse(ctrl.$viewValue || ''); + parser(ctrl.$viewValue); }); }