createValidation method

FxFieldValidator createValidation(
  1. String name, {
  2. bool required = false,
  3. List<FxFormValidator> validators = const [],
  4. String? label,
})

Implementation

FxFieldValidator createValidation(String name,
    {bool required = false, List<FxFormValidator> validators = const [], String? label}) {
  return (String? value) {
    label??=name.capitalize;
    String? error = getError(name);
    if (error != null) {
      return error;
    }

    if (required && (value == null || value.isEmpty)) {
      return "$label is required";
    }
    for (FxFormValidator validator in validators) {
      String? validationError = validator.validate(value);
      if (validationError != null) {
        return validationError;
      }
    }
    return null;
  };
}