diff --git a/src/.jshintrc b/src/.jshintrc index fd0170bc6661..d4912eafcf34 100644 --- a/src/.jshintrc +++ b/src/.jshintrc @@ -100,6 +100,7 @@ "assertNotHasOwnProperty": false, "getter": false, "getBlockElements": false, + "VALIDITY_STATE_PROPERTY": false, /* AngularPublic.js */ "version": false, diff --git a/src/Angular.js b/src/Angular.js index e09351d9b583..5916174504b3 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -13,6 +13,7 @@ -angularModule, -nodeName_, -uid, + -VALIDITY_STATE_PROPERTY, -lowercase, -uppercase, @@ -102,6 +103,10 @@ *
*/ +// The name of a form control's ValidityState property. +// This is used so that it's possible for internal tests to create mock ValidityStates. +var VALIDITY_STATE_PROPERTY = 'validity'; + /** * @ngdoc function * @name angular.lowercase diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index c1eaac7062b1..951a4dfa8865 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -435,15 +435,29 @@ function validate(ctrl, validatorName, validity, value){ return validity ? value : undefined; } +function testFlags(validity, flags) { + var i, flag; + if (flags) { + for (i=0; i'); formElm.append(inputElm); $compile(formElm)(scope); } + var attrs; + beforeEach(function() { currentSpec = this; }); + afterEach(function() { currentSpec = null; }); + beforeEach(module(function($compileProvider) { + $compileProvider.directive('attrCapture', function() { + return function(scope, element, $attrs) { + attrs = $attrs; + }; + }); + })); + beforeEach(inject(function($injector, _$sniffer_, _$browser_) { $sniffer = _$sniffer_; $browser = _$browser_; @@ -844,6 +862,33 @@ describe('input', function() { }); + it('should invalidate number if suffering from bad input', function() { + compileInput('', { + valid: false, + badInput: true + }); + + changeInputValueTo('10a'); + expect(scope.age).toBeUndefined(); + expect(inputElm).toBeInvalid(); + }); + + + it('should validate number if transition from bad input to empty string', function() { + var validity = { + valid: false, + badInput: true + }; + compileInput('', validity); + changeInputValueTo('10a'); + validity.badInput = false; + validity.valid = true; + changeInputValueTo(''); + expect(scope.age).toBeNull(); + expect(inputElm).toBeValid(); + }); + + describe('min', function() { it('should validate', function() {