Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(legacy): InputPhone fix format paste if value has space after plus sign #9634

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ describe('tuiCreateCompletePhoneInsertionPreprocessor + browser autofill', () =>
['+779002005577', '+7 (900) 200-55-77'],
['+789002005577', '+7 (900) 200-55-77'],
['+79002005577', '+7 (900) 200-55-77'],
['+ 790020055771', '+7 (900) 200-55-77'],
['+ 790020055771', '+7 (900) 200-55-77'],
];

tests.forEach(([before, after]) => {
Expand Down Expand Up @@ -59,6 +61,8 @@ describe('tuiCreateCompletePhoneInsertionPreprocessor + browser autofill', () =>
['+33+330123456789', '+33 01 23 45 67 89'],
['+3333 01 23 45 67 89', '+33 01 23 45 67 89'],
['+33330123456789', '+33 01 23 45 67 89'],
['+ 333301234567890', '+33 01 23 45 67 89'],
['+ 333301234567890', '+33 01 23 45 67 89'],
];

tests.forEach(([before, after]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,22 @@ describe('InputPhone', () => {
expect(testComponent.control.value).toBe('+71234567890');
});
});

describe('Entering the value with space after plus sign', () => {
it('value with space after plus sign', () => {
component.onValueChange('+ 712345678901');
fixture.detectChanges();

expect(testComponent.control.value).toBe('+71234567890');
});
});

describe('Entering the value with multiple spaces after plus sign', () => {
it('value with multiple spaces after plus sign', () => {
component.onValueChange('+ 712345678901');
fixture.detectChanges();

expect(testComponent.control.value).toBe('+71234567890');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export function tuiCreateCompletePhoneInsertionPreprocessor(

const trimCountryPrefix = (value: string): string =>
countryCode === '+7'
? value.replace(/^(\+?7?\s?8?)\s?/, '')
? value.replace(/^(\+?\s*7?\s?8?)\s?/, '')
: value.replace(
new RegExp(`^(\\+?${countryCode.replace('+', '')}?)\\s?`),
new RegExp(`^(\\+?\\s*${countryCode.replace('+', '')}?)\\s?`),
'',
);

Expand Down
Loading