diff --git a/modules/@angular/forms/src/validators.ts b/modules/@angular/forms/src/validators.ts index ba57904789232..c0eea11d5c86c 100644 --- a/modules/@angular/forms/src/validators.ts +++ b/modules/@angular/forms/src/validators.ts @@ -14,8 +14,9 @@ import {isPresent} from './facade/lang'; import {AbstractControl} from './model'; import {isPromise} from './private_import_core'; -function isEmptyInputValue(value: any) { - return value == null || typeof value === 'string' && value.length === 0; +function isEmptyInputValue(value: any): boolean { + // we don't check for string here so it also works with arrays + return value == null || value.length === 0; } /** diff --git a/modules/@angular/forms/test/validators_spec.ts b/modules/@angular/forms/test/validators_spec.ts index af44cf3efc7ba..d3b290c5e3512 100644 --- a/modules/@angular/forms/test/validators_spec.ts +++ b/modules/@angular/forms/test/validators_spec.ts @@ -48,6 +48,12 @@ export function main() { it('should accept zero as valid', () => { expect(Validators.required(new FormControl(0))).toBeNull(); }); + + it('should error on an empty array', + () => expect(Validators.required(new FormControl([]))).toEqual({'required': true})); + + it('should not error on a non-empty array', + () => expect(Validators.required(new FormControl([1, 2]))).toBeNull()); }); describe('requiredTrue', () => {