any<T> static method

ValidatorFunction any<T>(
  1. AnyValidatorFunctionTest<T> test
)

Gets 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 ValidatorFunction any<T>(AnyValidatorFunctionTest<T> test) {
  return AnyValidator<T>(test).validate;
}