summaryrefslogtreecommitdiffstats
path: root/portal-FE-common/src/app/shared/helpers/must-match-validator.ts
diff options
context:
space:
mode:
authorSudarshan Kumar <sudarshan.kumar@att.com>2020-01-23 17:06:22 +0530
committerSudarshan Kumar <sudarshan.kumar@att.com>2020-01-28 07:29:04 +0000
commit91e3434fc7c515416ff2da10d55acf1d2dbcde71 (patch)
treeac29f6ea8a20d06255c47ebdb8e4e2692621c0ab /portal-FE-common/src/app/shared/helpers/must-match-validator.ts
parent16c3ddbf7f9f644adc23b8f834e6453c5260ada6 (diff)
Adding new components with portal-FE-common
added layout, admins, functional-menu, portal-admins, plugins components along with helpers class, models, pipes and dependent angular services. Issue-ID: PORTAL-795 Change-Id: I8e9771fcee5d0e58c4a48711c943761f29ae48b8 Signed-off-by: Sudarshan Kumar <sudarshan.kumar@att.com>
Diffstat (limited to 'portal-FE-common/src/app/shared/helpers/must-match-validator.ts')
-rw-r--r--portal-FE-common/src/app/shared/helpers/must-match-validator.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/portal-FE-common/src/app/shared/helpers/must-match-validator.ts b/portal-FE-common/src/app/shared/helpers/must-match-validator.ts
new file mode 100644
index 00000000..70e9e1a4
--- /dev/null
+++ b/portal-FE-common/src/app/shared/helpers/must-match-validator.ts
@@ -0,0 +1,21 @@
+import { FormGroup } from '@angular/forms';
+
+// custom validator to check that two fields match
+export function MustMatch(controlName: string, matchingControlName: string) {
+ return (formGroup: FormGroup) => {
+ const control = formGroup.controls[controlName];
+ const matchingControl = formGroup.controls[matchingControlName];
+
+ if (matchingControl.errors && !matchingControl.errors.mustMatch) {
+ // return if another validator has already found an error on the matchingControl
+ return;
+ }
+
+ // set error on matchingControl if validation fails
+ if (control.value !== matchingControl.value) {
+ matchingControl.setErrors({ mustMatch: true });
+ } else {
+ matchingControl.setErrors(null);
+ }
+ }
+} \ No newline at end of file