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

Support intl-tel-input 19 #49

Merged
merged 5 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ See the [intl-tel-input repository](https://github.com/jackocnr/intl-tel-input)
[required]="true"
[options]="{
preferredCountries: ['ch'],
localizedCountries: { ch: 'Suisse' },
i18n: { ch: 'Suisse' },
onlyCountries: ['fr', 'ch']
}"
[onlyLocalized]="true"
Expand Down
82 changes: 74 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@angular/common": "^17.0.0",
"@angular/core": "^17.0.0",
"@angular/forms": "^17.0.0",
"intl-tel-input": "^18.0.0"
"intl-tel-input": "^19.0.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^17.0.0",
Expand Down
7 changes: 4 additions & 3 deletions src/lib/components/intl-tel-input.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch ! The linter should have warned...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe updating all packages will help

import { FormsModule, NgForm } from '@angular/forms';
import { By } from '@angular/platform-browser';
import { IntlTelInputComponent } from './intl-tel-input.component';
Expand Down Expand Up @@ -168,6 +168,7 @@ describe('IntlTelInputComponent', () => {

it('should be possible to set preferredCountries option', () => {
component.options = {
countrySearch: false,
preferredCountries: ['ch'],
onlyCountries: ['ch']
};
Expand All @@ -185,11 +186,11 @@ describe('IntlTelInputComponent', () => {
expect(element.getAttribute('data-country-code')).toBe(component.options.onlyCountries?.[0]);
});

it('should be possible to set localizedCountries option', () => {
it('should be possible to set i18n option', () => {
const localizedCountryName = 'Suisse';
component.options = {
preferredCountries: ['ch'],
localizedCountries: { ch: localizedCountryName },
i18n: { ch: localizedCountryName },
onlyCountries: ['ch']
};
component.ngAfterViewInit();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/intl-tel-input.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class IntlTelInputComponent implements AfterViewInit {
@Output() private E164PhoneNumberChange = new EventEmitter<string | null>();
@ViewChild('intlTelInput') private _inputElement!: ElementRef;
private _phoneNumber!: string;
private _intlTelInput: any;
public _intlTelInput: any;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should stay private

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oups my bad was debugging somethink and forget about it ....


private static modifyCountryData(): void {
(window as any).intlTelInputGlobals.getCountryData().forEach((country: CountryData) =>
Expand Down Expand Up @@ -65,7 +65,7 @@ export class IntlTelInputComponent implements AfterViewInit {

i18nizePhoneNumber(): void {
this.E164PhoneNumber = null;
if (this._intlTelInput.isValidNumber()) {
if (this._intlTelInput.isValidNumberPrecise()) {
this.E164PhoneNumber = this._intlTelInput.getNumber();
}
this.E164PhoneNumberChange.emit(this.E164PhoneNumber);
Expand Down
11 changes: 8 additions & 3 deletions src/lib/model/intl-tel-input-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export interface IntlTelInputOptions {
* Default = "polite"
*/
autoPlaceholder?: 'off' | 'polite' | 'aggressive';
/**
* Add a search input to the top of the dropdown, so users can filter the displayed countries.
* Default = true
*/
countrySearch?: boolean;
/**
* Change the placeholder generated by autoPlaceholder. Must return a string.
* Default = null
Expand Down Expand Up @@ -95,7 +100,7 @@ export interface IntlTelInputOptions {
* Allows to translate the countries by its given iso code e.g.:
* { 'de': 'Deutschland' }
*/
localizedCountries?: { [key: string]: string };
i18n?: { [key: string]: string };
/**
* Allow users to enter national numbers (and not have to think about
* international dial codes). Formatting, validation and placeholders still
Expand All @@ -118,7 +123,7 @@ export interface IntlTelInputOptions {
placeholderNumberType?: placeholderNumberType;
/**
* Specify the countries to appear at the top of the list.
* Default = ["us", "gb"]
* Note that this option is not compatible with the countrySearch feature, and so that needs to be disabled for this to work.
*/
preferredCountries?: string[];
/**
Expand All @@ -128,7 +133,7 @@ export interface IntlTelInputOptions {
* dial code separated.
* Default = false
*/
separateDialCode?: boolean;
showSelectedDialCode?: boolean;
/**
* Enable formatting/validation etc. by specifying the URL of the included utils.js script
* (or alternatively just point it to the file on cdnjs.com). The script is fetched when the page has finished
Expand Down
Loading