any<T> static method
Creates a validator that requires any element of the control's iterable value
satisfies test
.
Checks every element in control's value in iteration order, and marks
the control as valid if any of them make test
return true
,
otherwise marks the control as invalid.
Example with FormArray
final array = FormArray<String>([
FormControl<String>(value: ''),
FormControl<String>(value: ''),
], validators: [
Validators.any((String value) => value?.isNotEmpty)
]);
print(array.valid); // outputs: false
Example with FormControl
final control = FormControl<List<String>>(
value: [null, null, 'not empty'],
validators: [
Validators.any((String? value) => value?.isNotEmpty)
],
);
print(control.valid); // outputs: true
Implementation
static Validator<dynamic> any<T>(AnyValidatorFunctionTest<T> test) {
return AnyValidator<T>(test);
}