From a11fa35a3585f777a1b91caad38cbde92ffddb90 Mon Sep 17 00:00:00 2001 From: Christopher-walsh22 <106549296+Christopher-walsh22@users.noreply.github.com> Date: Mon, 8 Jan 2024 18:42:25 +0000 Subject: [PATCH 1/2] Fixing mandatory phone number bug --- .../contact-form/contact-form.component.ts | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/app/registration/contact-form/contact-form.component.ts b/src/app/registration/contact-form/contact-form.component.ts index 9d1fa42f3..d2a790a6f 100644 --- a/src/app/registration/contact-form/contact-form.component.ts +++ b/src/app/registration/contact-form/contact-form.component.ts @@ -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]); @@ -112,7 +112,7 @@ export class ContactFormComponent implements OnInit { email: ['', [Validators.required, Validators.pattern(Constants.emailValidationRegex)]], emailCheck: ['', [Validators.required]], phone: ['', [Validators.required]], - enablePhone: ['', [Validators.required]] + enablePhone: [false, [Validators.required]] }, { validators: [this.checkMatchEmails('email', 'emailCheck'), this.checkPhoneNumber('phone', 'enablePhone') ], @@ -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 { From 0ff9aa51bb1caefba6b3912d39917d0cac13165a Mon Sep 17 00:00:00 2001 From: Christopher-walsh22 <106549296+Christopher-walsh22@users.noreply.github.com> Date: Mon, 8 Jan 2024 19:27:04 +0000 Subject: [PATCH 2/2] Remove required validation from phone and enablePhone --- src/app/registration/contact-form/contact-form.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/registration/contact-form/contact-form.component.ts b/src/app/registration/contact-form/contact-form.component.ts index d2a790a6f..e3c794f67 100644 --- a/src/app/registration/contact-form/contact-form.component.ts +++ b/src/app/registration/contact-form/contact-form.component.ts @@ -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: [false, [Validators.required]] + phone: [''], + enablePhone: [false] }, { validators: [this.checkMatchEmails('email', 'emailCheck'), this.checkPhoneNumber('phone', 'enablePhone') ],