diff --git a/src/app/contact/contact.component.html b/src/app/contact/contact.component.html index 92ef14404731f318889e6797fef1c3c6046aafea..a254324c4fa3ae90696bb2a24c6b55da15a92f2c 100644 --- a/src/app/contact/contact.component.html +++ b/src/app/contact/contact.component.html @@ -33,7 +33,7 @@ autocomplete="on" [status]="contactForm.get('phone').value ? (contactForm.get('phone').invalid ? 'error' : 'success') : null" [value]="contactForm.get('phone').value" - (valueChange)="contactForm.get('phone').setValue($event); utils.modifyPhoneInput(contactForm, 'phone', $event)" + (valueChange)="contactForm.get('phone').setValue($event)" /> <app-input diff --git a/src/app/form/form-view/account-form/account-info/account-info.component.html b/src/app/form/form-view/account-form/account-info/account-info.component.html index 7d82fa96ed4f52a057904537e6105ac2d61540e1..c98c7efeb675d47e739701ea568671d5948c3047 100644 --- a/src/app/form/form-view/account-form/account-info/account-info.component.html +++ b/src/app/form/form-view/account-form/account-info/account-info.component.html @@ -35,11 +35,7 @@ [required]="true" [status]="accountForm.get('phone').value ? (accountForm.get('phone').invalid ? 'error' : 'success') : null" [value]="accountForm.get('phone').value" - (valueChange)=" - accountForm.get('phone').setValue($event); - utils.modifyPhoneInput(accountForm, 'phone', $event); - setValidationsForm() - " + (valueChange)="accountForm.get('phone').setValue($event); setValidationsForm()" /> </div> </form> diff --git a/src/app/form/form-view/structure-form/structure-contact/structure-contact.component.html b/src/app/form/form-view/structure-form/structure-contact/structure-contact.component.html index bdbbd687099d6e2b138189de06488fdb62ce2725..86067bbe9df33f5ab90732824edc4b750e52c8dc 100644 --- a/src/app/form/form-view/structure-form/structure-contact/structure-contact.component.html +++ b/src/app/form/form-view/structure-form/structure-contact/structure-contact.component.html @@ -21,7 +21,7 @@ type="tel" [status]="getContactPhoneStatus()" [value]="structureForm.get('contactPhone').value" - (valueChange)="utils.modifyPhoneInput(structureForm, 'contactPhone', $event); setValidationsForm()" + (valueChange)="structureForm.get('contactPhone').setValue($event); setValidationsForm()" /> </div> </form> diff --git a/src/app/form/orientation-form-view/global-components/structure-orientator/structure-orientator.component.ts b/src/app/form/orientation-form-view/global-components/structure-orientator/structure-orientator.component.ts index 55e12b573752ba443b3e06a8eb753dd7441d0dca..562921453a16882856686034f42679bcbda245b2 100644 --- a/src/app/form/orientation-form-view/global-components/structure-orientator/structure-orientator.component.ts +++ b/src/app/form/orientation-form-view/global-components/structure-orientator/structure-orientator.component.ts @@ -52,8 +52,9 @@ export class StructureOrientatorComponent implements OnInit { public updatedForm(field: string, value: string): void { if (field === 'structurePhone') { - this.utils.modifyPhoneInput(this.form, 'structurePhone', value); - } else this.form.get(field).patchValue(value); + value = this.utils.modifyPhoneValue(value); + } + this.form.get(field).patchValue(value); this.validatePage.emit(this.form.valid); } diff --git a/src/app/form/orientation-form-view/online-demarch/online-mediation/mediation-beneficiary-info/mediation-beneficiary-info.component.ts b/src/app/form/orientation-form-view/online-demarch/online-mediation/mediation-beneficiary-info/mediation-beneficiary-info.component.ts index ac62cd66779e410b71c6f04f35433fb03a83d676..ddc31962d3d9fbb06ee40462081d81d59edcf877 100644 --- a/src/app/form/orientation-form-view/online-demarch/online-mediation/mediation-beneficiary-info/mediation-beneficiary-info.component.ts +++ b/src/app/form/orientation-form-view/online-demarch/online-mediation/mediation-beneficiary-info/mediation-beneficiary-info.component.ts @@ -24,13 +24,14 @@ export class MediationBeneficiaryInfoComponent implements OnInit { return Boolean(this.form.get('email')); } public getSup(): string { - return this.isPhone() && this.isEmail() ? '1' : ''; + return this.isPhone() && this.isEmail() ? '1' : '*'; } public updatedForm(field: string, value: string): void { if (field === 'phone') { - this.utils.modifyPhoneInput(this.form, 'phone', value); - } else this.form.get(field).patchValue(value); + value = this.utils.modifyPhoneValue(value); + } + this.form.get(field).patchValue(value); this.checkValidation.emit(); } diff --git a/src/app/shared/components/input/input.component.ts b/src/app/shared/components/input/input.component.ts index f96f0ea0a8447dbdc23839435fee6bb35718639e..9f92ff241feed1508b32b53e91169d0457ff1727 100644 --- a/src/app/shared/components/input/input.component.ts +++ b/src/app/shared/components/input/input.component.ts @@ -1,5 +1,6 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { CustomRegExp } from 'src/app/utils/CustomRegExp'; +import { Utils } from '../../../utils/utils'; @Component({ selector: 'app-input', @@ -55,6 +56,8 @@ export class InputComponent implements OnInit { @Output() finishedEditing = new EventEmitter<string>(); + constructor(private utils: Utils) {} + public hasIconInField = false; private example = ''; @@ -80,6 +83,9 @@ export class InputComponent implements OnInit { this.setStatusSuccess(); } } + if (this.type === 'tel') { + this.value = this.utils.modifyPhoneValue(this.value); + } this.valueChange.emit(this.value); } diff --git a/src/app/utils/utils.ts b/src/app/utils/utils.ts index 9753d60b90c57ad53ab9dc81210a40bcec805472..36eedd9dcdb88f4e03ed1f6561021cae0064c395 100644 --- a/src/app/utils/utils.ts +++ b/src/app/utils/utils.ts @@ -17,17 +17,6 @@ export type CanExitResolver = (value: boolean) => void; providedIn: 'root', }) export class Utils { - public modifyPhoneInput(form: UntypedFormGroup, controlName: string, phoneNumber: string): void { - form.get(controlName).setValue(phoneNumber); - // Take length of phone number without spaces. - const phoneNoSpace = phoneNumber.replace(/\s/g, ''); - // Check to refresh every 2 number. - if (phoneNoSpace.length % 2 === 0) { - // Add space every 2 number - form.get(controlName).setValue(phoneNoSpace.replace(/(?!^)(?=(?:\d{2})+$)/g, ' ')); // NOSONAR - } - } - public modifyPhoneValue(phoneNumber: string): string { // Take length of phone number without spaces. const phoneNoSpace = phoneNumber.replace(/\s/g, '');