hasError method

bool hasError(
  1. String errorCode, [
  2. String? path
])

Reports whether the control with the given path has the specified errorCode.

If no path is given, this method checks for the error on the current control.

Example:

final form = FormGroup({
  'address': FormGroup({
    'street': FormControl<String>(validators: [Validators.required]),
  }),
});

final hasError = form.hasError(ValidationMessages.required, 'address.street');
print(hasError); // outputs: true

Implementation

bool hasError(String errorCode, [String? path]) {
  return getError(errorCode, path) != null;
}