diff --git a/src/app/crossValidator.service.ts b/src/app/crossValidator.service.ts
index 0ba55b7..8242487 100644
--- a/src/app/crossValidator.service.ts
+++ b/src/app/crossValidator.service.ts
@@ -19,4 +19,16 @@ export class CrossValidator {
return error;
};
}
+
+ public crossValidate() {
+ return (control: AbstractControl): ValidationErrors | null => {
+ if (!(control instanceof FormGroup)) {
+ return null;
+ }
+
+ const contactType = control.get('contactType')?.value;
+
+ if (contactType == "None") return null;
+ }
+ }
}
diff --git a/src/app/new-hotel/new-hotel.component.html b/src/app/new-hotel/new-hotel.component.html
index a72d1ed..c2ae134 100644
--- a/src/app/new-hotel/new-hotel.component.html
+++ b/src/app/new-hotel/new-hotel.component.html
@@ -5,24 +5,55 @@
{{ errorMessages['name'] }}
-
+
{{ errorMessages['description'] }}
-
+
{{ errorMessages['imageUrl'] }}
-
+
{{ errorMessages['price'] }}
-
+
{{ errorMessages['rating'] }}
-
+
@for (tag of getTags().controls; track tag) {
-
-
+
+
}
+
+ None
+ Email
+ SMS
+
+ @if (hotelForm.get("contactType")?.value == "Email") {
+
+
+
+
+
+
+ }
+ @if (hotelForm.get("contactType")?.value == "SMS") {
+
+
+
+
+
+
+ }
+
Cancel
diff --git a/src/app/new-hotel/new-hotel.component.ts b/src/app/new-hotel/new-hotel.component.ts
index b89763b..103e99f 100644
--- a/src/app/new-hotel/new-hotel.component.ts
+++ b/src/app/new-hotel/new-hotel.component.ts
@@ -67,10 +67,20 @@ export class NewHotelComponent {
price: new FormControl(0, Validators.required),
imageUrl: new FormControl("", Validators.required),
rating: new FormControl(0, Validators.required),
+ contactType: new FormControl('None'),
+ email: new FormControl(''),
+ emailConfirmation: new FormControl(''),
+ phone: new FormControl(''),
+ phoneConfirmation: new FormControl(''),
tags: new FormArray(tags)
}, { validators: new CrossValidator().onlyAllowNameAndDescriptionSame() })
this.hotelForm.valueChanges.subscribe(() => this.updateErrorMessages());
+ this.hotelForm.valueChanges.subscribe(() => this.formUpdated());
+ }
+
+ formUpdated() {
+ console.log(this.hotelForm.get("contactType")?.value);
}
getTags() {