or method
ValidationBuilder
or(
- Action<
ValidationBuilder> left, - Action<
ValidationBuilder> right, { - bool reverse = false,
Throws error only if left
and right
validators throw error same time.
If reverse
is true left builder's error will be displayed otherwise
right builder's error. Because this is default behaviour on most of the
programming languages.
Implementation
ValidationBuilder or(
Action<ValidationBuilder> left,
Action<ValidationBuilder> right, {
bool reverse = false,
}) {
// Create
final v1 = ValidationBuilder(locale: _locale);
final v2 = ValidationBuilder(locale: _locale);
// Configure
left(v1);
right(v2);
// Build
final v1cb = v1.build();
final v2cb = v2.build();
// Test
return add((value) {
final leftResult = v1cb(value);
if (leftResult == null) {
return null;
}
final rightResult = v2cb(value);
if (rightResult == null) {
return null;
}
return reverse == true ? leftResult : rightResult;
});
}