diff options
| author | Caitlin Potter | 2013-12-07 18:22:04 -0500 |
|---|---|---|
| committer | Pete Bacon Darwin | 2013-12-17 13:10:40 +0000 |
| commit | 5c97731a22ed87d64712e673efea0e8a05eae65f (patch) | |
| tree | 9ad87d0339a53be48a75ab99d62e7ec287e81d78 /test/ng/directive/selectSpec.js | |
| parent | b2e472e7a2e3389456278d8e6a18384a1d797f89 (diff) | |
| download | angular.js-5c97731a22ed87d64712e673efea0e8a05eae65f.tar.bz2 | |
fix(select): invalidate when 'multiple`, `required` and model is `[]`
When `multiple` attribute is set on a `<select>` control and the model value is an empty array,
we should invalidate the control. Previously, this directive was using incorrect logic for
determining if the model was empty.
Closes #5337
Diffstat (limited to 'test/ng/directive/selectSpec.js')
| -rw-r--r-- | test/ng/directive/selectSpec.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js index ac0cc70d..83591949 100644 --- a/test/ng/directive/selectSpec.js +++ b/test/ng/directive/selectSpec.js @@ -1215,6 +1215,30 @@ describe('select', function() { }); + it('should treat an empty array as invalid when `multiple` attribute used', function() { + createSelect({ + 'ng-model': 'value', + 'ng-options': 'item.name for item in values', + 'ng-required': 'required', + 'multiple': '' + }, true); + + scope.$apply(function() { + scope.value = []; + scope.values = [{name: 'A', id: 1}, {name: 'B', id: 2}]; + scope.required = true; + }); + expect(element).toBeInvalid(); + + scope.$apply(function() { + // ngModelWatch does not set objectEquality flag + // array must be replaced in order to trigger $formatters + scope.value = [scope.values[0]]; + }); + expect(element).toBeValid(); + }); + + it('should allow falsy values as values', function() { createSelect({ 'ng-model': 'value', |
