Skip to content

Commit

Permalink
luifNumber [fix] issue #35, bugs when input = null or NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
lucienbertin committed Oct 13, 2015
1 parent 02da747 commit 4661370
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions js/filters/genericFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
.filter('luifNumber', ['$sce', '$filter', function($sce, $filter) {
return function(_input, _precision, _placeholder) {
var placeholder = _placeholder === undefined ? '' : _placeholder;
var input = _input === undefined ? placeholder : _input;
// alert(_input + " " + (!!_input.isNaN && _input.isNaN()));
var input = _input === undefined || _input === null || _input != _input ? placeholder : _input; // the last check is to check if _input is NaN
var separator = $filter("number")(1.1,1)[1];
var precision = _precision === undefined ? 2 : _precision;

Expand All @@ -50,7 +51,7 @@
// the _input or the _placeholder was not parsable by the number $filter, just return input but trusted as html
return $sce.trustAsHtml(input + rightSpan);
}

var integerPart = text.split(separator)[0];
return $sce.trustAsHtml(integerPart + rightSpan);
};
Expand Down
2 changes: 2 additions & 0 deletions tests/spec/genericFilters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ describe('luif.timefilters', function(){
expect(luifNumber('a string',0).$$unwrapTrustedValue()).toEqual("a string<span style=\"opacity:0\"></span>");
});
it('should work with value = undefined', function(){
expect(luifNumber(0/0).$$unwrapTrustedValue()).toEqual("<span style=\"opacity:0\">.00</span>");
expect(luifNumber(null).$$unwrapTrustedValue()).toEqual("<span style=\"opacity:0\">.00</span>");
expect(luifNumber(undefined).$$unwrapTrustedValue()).toEqual("<span style=\"opacity:0\">.00</span>");
expect(luifNumber(undefined,undefined,0).$$unwrapTrustedValue()).toEqual("0<span style=\"opacity:0\">.00</span>");
expect(luifNumber(undefined,undefined,'nothing').$$unwrapTrustedValue()).toEqual("nothing<span style=\"opacity:0\">.00</span>");
Expand Down

0 comments on commit 4661370

Please sign in to comment.