Created
April 13, 2017 05:30
-
-
Save third774/c805a96fb3e2ee03952c6873f08a52fa to your computer and use it in GitHub Desktop.
Implementing global Custom Errors in ng-bootstrap-form-validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {BrowserModule} from "@angular/platform-browser"; | |
import {NgModule} from "@angular/core"; | |
import {FormsModule, ReactiveFormsModule} from "@angular/forms"; | |
import {HttpModule} from "@angular/http"; | |
import {NgBootstrapFormValidationModule} from "ng-bootstrap-form-validation"; | |
import {AppComponent} from "./app.component"; | |
import {CUSTOM_ERRORS} from "./custom-errors"; | |
@NgModule({ | |
declarations: [ | |
AppComponent | |
], | |
imports: [ | |
BrowserModule, | |
FormsModule, | |
ReactiveFormsModule, | |
NgBootstrapFormValidationModule.forRoot(CUSTOM_ERRORS), | |
HttpModule | |
], | |
providers: [], | |
bootstrap: [AppComponent] | |
}) | |
export class AppModule { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {ErrorMessage} from "ng-bootstrap-form-validation"; | |
export const CUSTOM_ERRORS: ErrorMessage[] = [ | |
{ | |
error: "required", | |
format: requiredFormat | |
}, { | |
error: "email", | |
format: emailFormat | |
} | |
]; | |
export function requiredFormat(label: string, error: any): string { | |
return `${label} IS MOST DEFINITELY REQUIRED!`; | |
} | |
export function emailFormat(label: string, error: any): string { | |
return `${label} doesn't look like a valid email address.`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment