Skip to content

Instantly share code, notes, and snippets.

@dancornilov
Created March 26, 2019 10:44
Show Gist options
  • Save dancornilov/0dab77269d68519606f40c92bcf5f624 to your computer and use it in GitHub Desktop.
Save dancornilov/0dab77269d68519606f40c92bcf5f624 to your computer and use it in GitHub Desktop.
Generate validator message
/**
* Check if the validator has a custom validation message
*
* @param errors
*
* @return string
*/
public message(errors: ValidationErrors | null): string {
const properties = Object.keys(errors);
let customMessage: boolean;
if (this.customValidation) {
customMessage = (properties.indexOf(this.customValidation.name) > -1);
}
return customMessage ? this.customValidation.text : `validators.${properties[0]}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment