checkField<F> method

Validator<S> checkField<F>(
  1. Selector<S, F?> selector,
  2. Validator<F> verification
)

Creates a new validator by nesting the provided one.

If both the calling validator and the additional check fail, the error produced by the calling is returned. Note: checkField is different from check in that it ignore the verification if the focused field is null. This is common when validating forms in which null represents a field which has not being visited.

Implementation

Validator<S> checkField<F>(
  Selector<S, F?> selector,
  Validator<F> verification,
) {
  final bypassingValidation = _makeOptional(verification);
  final Validator<S> fieldValidator = (S s) {
    final focus = selector(s);
    final result = bypassingValidation(focus);
    return result.map((_) => s);
  };
  return _join(this, fieldValidator);
}