fix(forms): Validators.required properly validate arrays (#13362)
Closes #12274
This commit is contained in:
parent
2dd6280ab8
commit
9898d8f6d9
@ -14,8 +14,9 @@ import {isPresent} from './facade/lang';
|
|||||||
import {AbstractControl} from './model';
|
import {AbstractControl} from './model';
|
||||||
import {isPromise} from './private_import_core';
|
import {isPromise} from './private_import_core';
|
||||||
|
|
||||||
function isEmptyInputValue(value: any) {
|
function isEmptyInputValue(value: any): boolean {
|
||||||
return value == null || typeof value === 'string' && value.length === 0;
|
// we don't check for string here so it also works with arrays
|
||||||
|
return value == null || value.length === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,6 +48,12 @@ export function main() {
|
|||||||
|
|
||||||
it('should accept zero as valid',
|
it('should accept zero as valid',
|
||||||
() => { expect(Validators.required(new FormControl(0))).toBeNull(); });
|
() => { 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', () => {
|
describe('requiredTrue', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user