intl-tel-input icon indicating copy to clipboard operation
intl-tel-input copied to clipboard

How to set initial country based on country code?

Open C-Guards opened this issue 2 years ago • 2 comments

Steps to reproduce

when I initialize country selection it by default selects the first country, I want to provide +962 and it will select Jordan(jordan flag). I looked at the documentation, I have the country code, but not the country name.

C-Guards avatar Aug 02 '22 12:08 C-Guards

Use preferredCountries or defaultCountry to accomplish what you need.

FesterCluck avatar Aug 18 '22 07:08 FesterCluck

p

I don't think preferredCountries would help, but for defaultCountry, I tried to use it, but it requires info to pass which I didn't store it in DB.

samerlol avatar Aug 18 '22 07:08 samerlol

The option is called initialCountry. If you always want to set it to Jordan, you just need to google the iso 2 letter country code for Jordan, which appears to be "jo". Or if you want to map an international dial code to an ISO2 alpha country code, you can do that with getCountryData static method - see a related example here: https://intl-tel-input.com/node_modules/intl-tel-input/examples/gen/country-sync.html

jackocnr avatar Sep 30 '22 13:09 jackocnr