intl-tel-input
intl-tel-input copied to clipboard
How to set initial country based on country code?
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.
Use preferredCountries or defaultCountry to accomplish what you need.
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.
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