Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save shemmjunior/50e628c91260e5a824d859c6eb3a3d40 to your computer and use it in GitHub Desktop.

Select an option

Save shemmjunior/50e628c91260e5a824d859c6eb3a3d40 to your computer and use it in GitHub Desktop.
Get error fields on form validation
getFormValidationErrors(): any {
const errors = [];
Object.keys(this.tenantForm.controls).forEach(key => {
const controlErrors: ValidationErrors = this.tenantForm.get(key).errors;
if (controlErrors != null) {
Object.keys(controlErrors).forEach(keyError => {
errors.push({
'field': key,
'error': keyError,
'value': controlErrors[keyError]
});
this.createErrorNotification('bottomLeft', `You have an error in the ${key} field`);
});
}
});
return JSON.stringify(errors);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment