validator method
Validates the given value and returns the result.
Don't call directly, call validate instead.
Implementation
@override
EskResult validator(dynamic value) {
final superRes = super.validator(value);
if (superRes.isNotValid) return superRes;
for (final field in fields) {
final mapValue = value[field.id];
// If the field is nullable, we can skip validation if the value is null
if (mapValue == null && field.isNullable) continue;
print(
"Validating field: ${field.id}, value: $mapValue, with field: $field",
);
final result = field.validate(mapValue);
if (result.isValid) continue;
String error = '';
if (field is EskMap) {
error += '${field.id}.${result.error}';
} else {
error += '${field.id} to be ${result.error}';
}
return EskResult(
isValid: result.isValid,
error: error,
value: mapValue,
);
}
return EskResult.valid(value);
}