Skip to content
Snippets Groups Projects
Commit 7de96494 authored by Etienne LOUPIAS's avatar Etienne LOUPIAS
Browse files

fix(profile): format tel number for all phone inputs

parent 51c1bf41
No related branches found
No related tags found
1 merge request!907V3.2.0
......@@ -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
......
......@@ -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>
......@@ -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>
......@@ -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);
}
......
......@@ -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();
}
......
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);
}
......
......@@ -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, '');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment