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

Default global icon for invalid dial code #1646

Closed
minhluan259 opened this issue Jun 6, 2024 · 8 comments
Closed

Default global icon for invalid dial code #1646

minhluan259 opened this issue Jun 6, 2024 · 8 comments

Comments

@minhluan259
Copy link

Plugin version

e.g. v23.0.10 (please try latest version)

Steps to reproduce

  1. Set default telephone number 12345
  2. Initial intl-tel-input on page load

Expected behaviour

Display a global icon if there is a default phone number already set with an invalid dial code.
Screenshot_10

Actual behaviour

Only arrow dropdown showing

@jackocnr
Copy link
Owner

jackocnr commented Jun 6, 2024

If you can find the minimal set of code that reproduces the problem and put that in a CodePen, then I'd be happy to take a look. Here is an example pen with the plugin up and running - feel free to fork this if it helps.

@jackocnr
Copy link
Owner

jackocnr commented Jun 6, 2024

It seems to work fine here: https://codepen.io/jackocnr/pen/NWVgMRp?editors=1010

So I'm not sure what the problem is. Can you reproduce it in a codepen?

@minhluan259
Copy link
Author

The problem occurs when I use https://ipinfo.io/json

const input = document.querySelector("#phone");

const iti = window.intlTelInput(input, {
  utilsScript:
    "https://cdn.jsdelivr.net/npm/[email protected]/build/js/utils.js",
  initialCountry: "auto",
  nationalMode: 1,
  strictMode: 1,
  separateDialCode: 1,
  autoPlaceholder: "aggressive",
  geoIpLookup: (callback) => {
    fetch("https://ipinfo.io/json")
      .then(res => res.json())
      .then(data => callback(data.country.toLowerCase()))
      .catch(() => callback("us"));
  }
});

// store the instance variable so we can access it in the console e.g. window.iti.getNumber()
window.iti = iti;

@jackocnr
Copy link
Owner

jackocnr commented Jun 6, 2024

Yes well it doesn't make sense to initialise the plugin with a phone number in the input, and then to set initialCountry=auto. If you already have a number, then you must already know the country, so either you (A) include the international dial code in the initial input value, which will automatically update the selected country (recommended), or (B) use initialCountry to set the correct country for the given number.

@jackocnr jackocnr closed this as completed Jun 6, 2024
@minhluan259
Copy link
Author

Initialize the plugin with a phone number in the input field in cases where we have a list of registered users with phone numbers but without country dial codes. Users will need to manually update the dial code after we integrate this plugin. Therefore, only the arrow showing may result in poor user experience.

@jackocnr
Copy link
Owner

jackocnr commented Jun 7, 2024

Ok I'll take a look when I have a moment, and try to get it so it always shows either a flag or the globe icon no matter what initialisation options are used.

@jackocnr
Copy link
Owner

jackocnr commented Jun 7, 2024

Fix released in v23.0.11 - give it a try and let me know if it works for you!

@minhluan259
Copy link
Author

Confirmed, it works. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants