From aba9bb2a241f832d1b09d75e05973a985b817cc1 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 15 Nov 2011 11:19:37 -0800 Subject: fix(input): treat all not number model as blank --- src/widget/input.js | 6 +++--- test/widget/inputSpec.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/widget/input.js b/src/widget/input.js index fb4cc0d4..3f25f09f 100644 --- a/src/widget/input.js +++ b/src/widget/input.js @@ -594,9 +594,9 @@ function numericRegexpInputType(regexp, error) { }; widget.$parseModel = function() { - if (isNumber(widget.$modelValue)) { - widget.$viewValue = '' + widget.$modelValue; - } + widget.$viewValue = isNumber(widget.$modelValue) + ? '' + widget.$modelValue + : ''; }; }]; } diff --git a/test/widget/inputSpec.js b/test/widget/inputSpec.js index 085cb2ea..dfbc506a 100644 --- a/test/widget/inputSpec.js +++ b/test/widget/inputSpec.js @@ -449,6 +449,18 @@ describe('widget: input', function() { }); }); + describe('number', function(){ + it('should clear number on non-number', inject(function($compile, $rootScope){ + $rootScope.value = 123; + var element = $compile('')($rootScope); + $rootScope.$digest(); + expect(element.val()).toEqual('123'); + $rootScope.value = undefined; + $rootScope.$digest(); + expect(element.val()).toEqual(''); + })); + }); + it('should ignore text widget which have no name', function() { compile(''); -- cgit v1.2.3