webcat12345 / ngx-intl-tel-input

Phone number input field to support international numbers, Angular
MIT License
213 stars 339 forks source link

auto country select isn't working as expected #176

Closed akashjain12366 closed 4 years ago

akashjain12366 commented 5 years ago

I have set my preferred country as UK and when start typing 01980.. it selects Guernsey country. If I type +919876 it selects India which works great. I think this may be because of duplication of country codes. Any way we can exclude some countries from list of countries or way to show only selected countries in list. If I set enableAutoCountrySelect to false then validate correctly against the selected country. But I wanted to this feature which selects country as user start typing. This is how my code looks like.

<ngx-intl-tel-input
  [cssClass]="'custom'"
  [preferredCountries]="['gb']"
  [enableAutoCountrySelect]="true"
  [enablePlaceholder]="true"
  name="'testPhone'"
  formControlName="phone"
></ngx-intl-tel-input>

There is one more thing, I would like to know is how can we provide an event onChange of field value?

Thanks, Akash

prambhan commented 5 years ago

Hey @akashjain12366,

Even I faced this issue of Guernsey having same country code as UK. I found a workaround by creating a list of countries required in my app and passing it for property "onlyCountries". Hope this helps.

<ngx-intl-tel-input [cssClass]="'custom-phone-input'" [preferredCountries]="['gb', 'us']" [onlyCountries]="onlyCountries" [enableAutoCountrySelect]="true" name="phone" formControlName="phone">

export const onlyCountries = ['af', 'al', 'dz', 'as', 'ad', 'ao', 'ai', 'ag', 'ar', 'am', 'aw', 'au', 'at', 'az', 'bs', 'bh', 'bd', 'bb', 'by', 'be', 'bz', 'bj', 'bm', 'bt', 'bo', 'ba', 'bw', 'br', 'io', 'vg', 'bn', 'bg', 'bf', 'bi', 'kh', 'cm', 'ca', 'cv', 'bq', 'ky', 'cf', 'td', 'cl', 'cn', 'cx', 'cc', 'co', 'km', 'cd', 'cg', 'ck', 'cr', 'ci', 'hr', 'cu', 'cw', 'cy', 'cz', 'dk', 'dj', 'dm', 'do', 'ec', 'eg', 'sv', 'gq', 'er', 'ee', 'et', 'fk', 'fo', 'fj', 'fi', 'fr', 'gf', 'pf', 'ga', 'gm', 'ge', 'de', 'gh', 'gi', 'gr', 'gl', 'gd', 'gp', 'gu', 'gt', 'gn', 'gw', 'gy', 'ht', 'hn', 'hk', 'hu', 'is', 'in', 'id', 'ir', 'iq', 'ie', 'il', 'it', 'jm', 'jp', 'jo', 'kz', 'ke', 'ki', 'xk', 'kw', 'kg', 'la', 'lv', 'lb', 'ls', 'lr', 'ly', 'li', 'lt', 'lu', 'mo', 'mk', 'mg', 'mw', 'my', 'mv', 'ml', 'mt', 'mh', 'mq', 'mr', 'mu', 'yt', 'mx', 'fm', 'md', 'mc', 'mn', 'me', 'ms', 'ma', 'mz', 'mm', 'na', 'nr', 'np', 'nl', 'nc', 'nz', 'ni', 'ne', 'ng', 'nu', 'nf', 'kp', 'mp', 'no', 'om', 'pk', 'pw', 'ps', 'pa', 'pg', 'py', 'pe', 'ph', 'pl', 'pt', 'pr', 'qa', 're', 'ro', 'ru', 'rw', 'bl', 'sh', 'kn', 'lc', 'mf', 'pm', 'vc', 'ws', 'sm', 'st', 'sa', 'sn', 'rs', 'sc', 'sl', 'sg', 'sx', 'sk', 'si', 'sb', 'so', 'za', 'kr', 'ss', 'es', 'lk', 'sd', 'sr', 'sj', 'sz', 'se', 'ch', 'sy', 'tw', 'tj', 'tz', 'th', 'tl', 'tg', 'tk', 'to', 'tt', 'tn', 'tr', 'tm', 'tc', 'tv', 'vi', 'ug', 'ua', 'ae', 'gb', 'us', 'uy', 'uz', 'vu', 'va', 've', 'vn', 'wf', 'eh', 'ye', 'zm', 'zw', 'ax' ];

zaizac commented 5 years ago

There's an issue as well to the countries with 4 digit dial code and starts with +1. Country code is considered as US. (ex. American Samoa, Antigua and Barbuda etc.)

pasevin commented 5 years ago

@akashjain12366 @prambhan can you verify it is now working as expected with the latest update?

prambhan commented 5 years ago

Hello,

In Karma test cases, I am getting blow issues. Can anyone help how to reoslve it please?

TypeError: undefined is not a constructor (evaluating '_this.onlyCountries.includes(c.iso2)') (line 1369)

Thanks

EwerthonSantana commented 2 years ago

i have the same problem, when code number start with 3 digits like canada (506) xxx-xxxx the flag in dropdown change to us every time when i write in input with enableAutoCountrySelect is true ;-;