You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 5, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+60-19Lines changed: 60 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,9 +37,13 @@ export class AppModule {
37
37
}
38
38
```
39
39
40
-
## Usage
40
+
## Basics
41
41
42
-
### Basics
42
+
### Default Errors
43
+
44
+
By default, the validators found on the `Validators` class from `@angular/forms` module are handled for you out of the box. All you need to do is import the module.
45
+
46
+
### Usage
43
47
ng-bootstrap-form-validation works by using the `form-group` Bootstrap class on your divs as component selector, and projecting the content into a component which handles form validation feedback for you.
44
48
45
49
The `has-error` and `has-success` classes are automatically added or removed to your `form-group` based on whether or not the input is valid, and is both `touched` and `dirty`.
@@ -110,32 +114,69 @@ export class BasicExampleComponent implements OnInit {
110
114
</div>
111
115
```
112
116
113
-
###Custom Messages
117
+
## Custom Error Messages
114
118
115
-
Optionally, you can pass an `ErrorMessage` array into the `.forRoot()` method in your `app.module.ts` to provide custom errors across your entire app. The `ErrorMessage` interface looks like this:
119
+
### Global Custom Errors
116
120
121
+
Optionally, you can pass an `ErrorMessage` array into the `.forRoot()` method in your `app.module.ts` to provide custom errors across your entire app. In order for this to be AOT compatable, the function definitions **must** be exported. see below for an example
122
+
123
+
`custom-errors.ts`
117
124
```ts
118
-
/**
119
-
* Interface for creating validation messages
120
-
*/
121
-
exportinterfaceErrorMessage {
122
-
/**
123
-
* The error key to look for on the FormControl.errors object
124
-
*/
125
-
error:string;
126
-
/**
127
-
* The message string function to create the validation message to be displayed.
128
-
* @param{string}label The text from the first <label> tag found within the .form-group
129
-
* @param{*}error The value accessed from FormControl.errors[error] using ErrorMessage.error as the key
In addition to providing custom errors at the top level using the `.forRoot()` method,
136
177
you can provide custom error messages to a specific control by binding to the
137
178
`customErrorMessages` directive on the `.form-group` element. Modifying the basic
138
-
example above, we can provide a one time custom error message to a specific `.form-group`
179
+
example above, we can provide a one time custom error message to a specific `.form-group`. Unline the global custom error messages, these do not need to be individually exported.
0 commit comments