Skip to content

Commit

Permalink
fix(input): fix numeric model md-maxlength validation
Browse files Browse the repository at this point in the history
  • Loading branch information
devversion committed Feb 13, 2016
1 parent 4a2e558 commit 81b8d41
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/input/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ function mdMaxlengthDirective($animate, $mdUtil) {
if (!angular.isNumber(maxlength) || maxlength < 0) {
return true;
}
return ( modelValue || element.val() || viewValue || '' ).length <= maxlength;
return ( modelValue || element.val() || viewValue || '' ).toString().length <= maxlength;
};
});

Expand Down
18 changes: 18 additions & 0 deletions src/components/input/input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,24 @@ describe('md-input-container directive', function() {
expect(getCharCounter(el).text()).toBe('3/5');
});

it('should work with a numeric model value', function() {
var el = $compile(
'<form name="form">' +
'<md-input-container>' +
'<input md-maxlength="5" ng-model="foo" name="foo">' +
'</md-input-container>' +
'</form>')(pageScope);

pageScope.$apply();

// Flush any pending $mdUtil.nextTick calls
$timeout.flush();

pageScope.$apply('foo = 1234');
expect(getCharCounter(el).text()).toBe('4/5');
expect(pageScope.form.foo.$error['md-maxlength']).toBeFalsy();
});

it('should render correct character count when value is a number', function() {
var template =
'<md-input-container>' +
Expand Down

0 comments on commit 81b8d41

Please sign in to comment.