aboutsummaryrefslogtreecommitdiffstats
path: root/test/ng/directive/inputSpec.js
diff options
context:
space:
mode:
authorPete Bacon Darwin2013-09-25 12:49:55 +0100
committerVojta Jina2013-10-07 16:47:51 -0700
commitb56b21a898b3c77589a48a290271f9dc181dafe8 (patch)
treee4d62493edf0497f9ea57ff202e219f485bd3808 /test/ng/directive/inputSpec.js
parent2b5ce84fca7b41fca24707e163ec6af84bc12e83 (diff)
downloadangular.js-b56b21a898b3c77589a48a290271f9dc181dafe8.tar.bz2
fix(input): `false` is no longer an empty value by default
`checkboxInputType` and `ngList` directives need to have special logic for whether they are empty or not. Previously this had been hard coded into their own directives or the `ngRequired` directive. This made it difficult to handle these special cases. This change factors out the question of whether an input is empty into a method `$isEmpty` on the `ngModelController`. The `ngRequired` directive now uses this method when testing for validity and directives, such as `checkbox` or `ngList` can override it to apply logic specific to their needs. Closes #3490, #3658, #2594
Diffstat (limited to 'test/ng/directive/inputSpec.js')
-rw-r--r--test/ng/directive/inputSpec.js33
1 files changed, 31 insertions, 2 deletions
diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js
index facc2b80..c94eb9b8 100644
--- a/test/ng/directive/inputSpec.js
+++ b/test/ng/directive/inputSpec.js
@@ -998,6 +998,16 @@ describe('input', function() {
expect(scope.list).toEqual([]);
});
+ it('should be invalid if required and empty', function() {
+ compileInput('<input type="text" ng-list ng-model="list" required>');
+ changeInputValueTo('');
+ expect(scope.list).toBeUndefined();
+ expect(inputElm).toBeInvalid();
+ changeInputValueTo('a,b');
+ expect(scope.list).toEqual(['a','b']);
+ expect(inputElm).toBeValid();
+ });
+
it('should allow custom separator', function() {
compileInput('<input type="text" ng-model="list" ng-list=":" />');
@@ -1090,10 +1100,29 @@ describe('input', function() {
it('should set $invalid when model undefined', function() {
- compileInput('<input type="text" ng-model="notDefiend" required />');
+ compileInput('<input type="text" ng-model="notDefined" required />');
scope.$digest();
expect(inputElm).toBeInvalid();
- })
+ });
+
+
+ it('should allow `false` as a valid value when the input type is not "checkbox"', function() {
+ compileInput('<input type="radio" ng-value="true" ng-model="answer" required />' +
+ '<input type="radio" ng-value="false" ng-model="answer" required />');
+
+ scope.$apply();
+ expect(inputElm).toBeInvalid();
+
+ scope.$apply(function() {
+ scope.answer = true;
+ });
+ expect(inputElm).toBeValid();
+
+ scope.$apply(function() {
+ scope.answer = false;
+ });
+ expect(inputElm).toBeValid();
+ });
});