fix(input): treat all not number model as blank

This commit is contained in:
Misko Hevery 2011-11-15 11:19:37 -08:00
parent 5857c44e0c
commit aba9bb2a24
2 changed files with 15 additions and 3 deletions

View file

@ -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
: '';
};
}];
}

View file

@ -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('<input type="number" ng:model="value" >')($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('<input type="text"/>');