Skip to content

Commit

Permalink
BRS-309: Mandatory Phone number bug (#310)
Browse files Browse the repository at this point in the history
* Fixing mandatory phone number bug

* Remove required validation from phone and enablePhone
  • Loading branch information
Christopher-walsh22 authored Jan 8, 2024
1 parent 53cd4c1 commit e4ce22e
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/app/registration/contact-form/contact-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ export class ContactFormComponent implements OnInit {
phoneControl.setValue('');
}
});
this.myForm.get('enablePhone').valueChanges.subscribe((enablePhoneValue) => {
this.myForm.get('enablePhone').valueChanges.subscribe((enablePhone) => {
const phoneControl = this.myForm.get('phone');
if (enablePhoneValue) {
if (enablePhone) {
phoneControl.setValidators([Validators.required, this.phoneValidator]);
} else {
phoneControl.setValidators([Validators.required]);
Expand All @@ -111,8 +111,8 @@ export class ContactFormComponent implements OnInit {
lastName: ['', Validators.required],
email: ['', [Validators.required, Validators.pattern(Constants.emailValidationRegex)]],
emailCheck: ['', [Validators.required]],
phone: ['', [Validators.required]],
enablePhone: ['', [Validators.required]]
phone: [''],
enablePhone: [false]
},
{
validators: [this.checkMatchEmails('email', 'emailCheck'), this.checkPhoneNumber('phone', 'enablePhone') ],
Expand Down Expand Up @@ -192,16 +192,27 @@ export class ContactFormComponent implements OnInit {
}

submit(): void {
const combinedValue = this.dialCode + this.myForm.get('phone').value.number;
this.saving = true;
const obj = {
firstName: this.myForm.get('firstName').value,
lastName: this.myForm.get('lastName').value,
email: this.myForm.get('email').value,
phone: `+${this.justNumbers(combinedValue)}`,
captchaJwt: this.captchaJwt
};
if (this.myForm.get('enablePhone').value) {
const combinedValue = this.dialCode + this.myForm.get('phone').value.number;
this.saving = true;
const obj = {
firstName: this.myForm.get('firstName').value,
lastName: this.myForm.get('lastName').value,
email: this.myForm.get('email').value,
phone: `+${this.justNumbers(combinedValue)}`,
captchaJwt: this.captchaJwt
};
this.emitter.emit(obj);
} else {
this.saving = true;
const obj = {
firstName: this.myForm.get('firstName').value,
lastName: this.myForm.get('lastName').value,
email: this.myForm.get('email').value,
captchaJwt: this.captchaJwt
};
this.emitter.emit(obj);
}
}

captchaValidated(event): void {
Expand Down

0 comments on commit e4ce22e

Please sign in to comment.