validateAttribute method

dynamic validateAttribute(
  1. String attribute,
  2. dynamic value
)

Validate a form attribute against its validation rules.

The validateAttribute function is used to validate a form attribute's value against its associated validation rules. It iterates through the validation rules for the specified attribute, validates the provided value against each rule, and adds error messages if any validation rule fails.

Parameters:

  • attribute: The identifier of the form attribute to be validated.
  • value: The value to be validated for the specified form attribute.

Implementation

validateAttribute(String attribute, dynamic value) {
  final errMsg = <String>[];
  for (final rule in getRule(attribute)) {
    final errorMessage = _validateAttribute(attribute, value, rule);
    if (errorMessage != null) {
      errMsg.add(errorMessage);
    }
  }
  if (errMsg.isNotEmpty) {
    setErrorMessages(attribute, errMsg);
  } else {
    clearErrorMessages(attribute);
  }
}