createValidation method
FxFieldValidator
createValidation(
- String name, {
- bool required = false,
- List<
FxFormValidator> validators = const [], - 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;
};
}