Skip to content

Commit 467f429

Browse files
committed
changes
1 parent 4af65f5 commit 467f429

File tree

18 files changed

+36
-80230
lines changed

18 files changed

+36
-80230
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# dependencies
99
/node_modules
1010

11+
1112
# IDEs and editors
1213
/.idea
1314
.project
@@ -33,6 +34,8 @@ npm-debug.log
3334
yarn-error.log
3435
testem.log
3536
/typings
37+
*.webm
38+
*.vlc
3639

3740
# System Files
3841
.DS_Store

README.md

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,24 @@
1-
# Validation-Directive-in-Angular-6
1+
# Validation-Tooltip-Directive-in-Angular-6
22

33
## RUN Application
44

55
```
6-
ng serve --port 4201
7-
http://localhost:4201
6+
ng serve
7+
http://localhost:4200
88
```
99

1010
## Mockdata
11-
validationerrors.json in assets folder
11+
fieldInfoContent.json in assets folder
1212

1313
```
1414
{
15-
"validationErrors": {
16-
"firstName-required" : "Firstname is a required field",
17-
"firstName-minlength" : "Firstname must have 2 characters",
18-
"firstName-maxlength" : "Firstname can have maximum 30 characters",
19-
20-
"lastName-required" : "Lastname is a required field",
21-
"lastName-minlength" : "Lastname must have 2 characters",
22-
"lastName-maxlength" : "Lastname can have maximum 30 characters",
23-
24-
"emailId-required": "Email is a required field",
25-
"emailId-email": "Email is not in valid format",
26-
"emailId-minlength" : "Email must have 6 characters",
27-
28-
"mobile-required" : "Mobile is a required field",
29-
"mobile-minlength" : "Mobile must have 10 characters",
30-
31-
"password-required" : "Password is a required field",
32-
"password-minlength" : "Password must have 6 characters",
33-
"password-maxlength" : "Password can have maximum 20 characters"
15+
"fieldInfo": {
16+
"firstName" : "Firstname is a required field",
17+
"middleName": "middleName is not a required field",
18+
"lastName" : "Lastname is a required field",
19+
"emailId": "Email is a required field",
20+
"mobile" : "Mobile is a required field",
21+
"password" : "Password is a required field"
3422
}
3523
}
3624
```
@@ -52,22 +40,22 @@ export class ValidationMessageService {
5240
}
5341
```
5442

55-
###Load all messages from validationerrors.json using the following code which is written in register.component.ts
43+
###Load all messages from fieldInfoContent.json using the following code which is written in register.component.ts
5644

5745
```
5846
validationErrorMsg() {
59-
this.apiService.getValidationErrorMessage().then(
60-
(res) => {
61-
if (this.validErrorMsgService.validationErrorObj.length === 0) {
62-
this.validErrorMsgService.validationErrorObj = res['validationErrors'];
63-
console.log('Validation Error => ', this.validErrorMsgService.validationErrorObj);
64-
}
65-
}, (error) => {
66-
this.errorData = this.sharedService.getErrorKeys(error.statusText);
67-
});
47+
this.apiService.getFieldInfoMessage().then(
48+
(res) => {
49+
if (this.validErrorMsgService.validationErrorObj.length === 0) {
50+
this.fieldInfoMsgArr = res['fieldInfo'];
51+
console.log('Field Info Array => ', this.fieldInfoMsgArr);
52+
this.isLoading = false;
53+
}
54+
}, (error) => {
55+
console.log(error);
56+
this.isLoading = false;
57+
});
6858
}
6959
```
7060

7161
Now i have to create a directive validation-label.directive.ts will run on the status change of the form control elements. It requires a ‘formControlName’ attribute added to the control. This will be used to used to construct the key that will be passed to the validation service class. The above directive will handle the change/blur events on controls and displays the messages accordingly.
72-
73-
Few things to notice in this class are that I defined ‘statusChangeSubscription’ to listen to status changes on the control and remove/add error message depending on the status (INVALID). Also we unsubscribe it on destroy class. And I defined a helper method to construct the message key, get the error message from service class and display it on the view.

dist/validation-tooltip/3rdpartylicenses.txt

Lines changed: 1 addition & 310 deletions
Large diffs are not rendered by default.

dist/validation-tooltip/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<meta name="viewport" content="width=device-width, initial-scale=1">
99
<link rel="icon" type="image/x-icon" href="favicon.ico">
1010
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
11-
</head>
11+
<link rel="stylesheet" href="styles.0a33fa57bcd5629c58f5.css"></head>
1212
<body>
1313
<app-root></app-root>
14-
<script type="text/javascript" src="runtime.js"></script><script type="text/javascript" src="polyfills.js"></script><script type="text/javascript" src="styles.js"></script><script type="text/javascript" src="vendor.js"></script><script type="text/javascript" src="main.js"></script></body>
14+
<script type="text/javascript" src="runtime.a66f828dca56eeb90e02.js"></script><script type="text/javascript" src="polyfills.2f4a59095805af02bd79.js"></script><script type="text/javascript" src="main.d120d507a5b3bad5a176.js"></script></body>
1515
</html>

dist/validation-tooltip/main.js

Lines changed: 0 additions & 653 deletions
This file was deleted.

dist/validation-tooltip/main.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)