diff --git a/src/app/crossValidator.service.ts b/src/app/crossValidator.service.ts new file mode 100644 index 0000000..0ba55b7 --- /dev/null +++ b/src/app/crossValidator.service.ts @@ -0,0 +1,22 @@ +import { AbstractControl, FormGroup, ValidationErrors, ValidatorFn } from "@angular/forms"; + +export class CrossValidator { + public onlyAllowNameAndDescriptionSame() { + return (control: AbstractControl): ValidationErrors | null => { + if (!(control instanceof FormGroup)) { + return null; + } + + const name = control.get('name')?.value; + const description = control.get('description')?.value; + + console.log(name, description); + + const error = name !== description ? { mismatch: true } : null; + + console.log(error); + + return error; + }; + } +} diff --git a/src/app/new-hotel/new-hotel.component.html b/src/app/new-hotel/new-hotel.component.html index 1e7e9a1..a72d1ed 100644 --- a/src/app/new-hotel/new-hotel.component.html +++ b/src/app/new-hotel/new-hotel.component.html @@ -1,6 +1,8 @@
Create Hotel