run<TKey> static method

ErrMap<TKey> run<TKey>(
  1. List<LoFormBaseValidator<TKey>> validators,
  2. ValMap<TKey> values
)

Runs all validators on values, then return the error messages or null accordingly.

Implementation

static ErrMap<TKey> run<TKey>(
  List<LoFormBaseValidator<TKey>> validators,
  ValMap<TKey> values,
) {
  final ErrMap<TKey> errors = {};

  for (final validator in validators) {
    final localErrors = validator.validate(values) ?? {};

    // Prevent overwriting errors
    localErrors.removeWhere(
      (key, value) => errors[key] != null,
    );

    errors.addAll(localErrors);
  }

  return errors;
}