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

Formatting does not return country to default #1654

Closed
HKallaste opened this issue Jun 12, 2024 · 3 comments
Closed

Formatting does not return country to default #1654

HKallaste opened this issue Jun 12, 2024 · 3 comments

Comments

@HKallaste
Copy link

Plugin version

v23.0.4

Steps to reproduce

  1. An input that's been initialized
  2. Call one of the functions that formats the field e.g. setNumber
  3. Change the content of the input via js (for example model gets opened with different values)
  4. Call setNumber again

Expected behaviour

If there is a valid country code: it'll pick out the country for it,
if not: then it would reset to the default

Actual behaviour

If you first open a number that lacks the code, it'll stay as default as intended.
If you open a number that has the code, and after open one without it - the country will still be set to the previous number's country after the format.

Initialisation options

countryOrder: ["ee", "fi", "se", "no", "dk", "de", "gb"],
countrySearch: false,
utilsScript: "https://cdn.jsdelivr.net/npm/[email protected]/build/js/utils.js",
nationalMode: false, (added due to the leading 0 causing issues)

@jackocnr
Copy link
Owner

Sorry I don't understand the issue.

Following your instructions, on the demo site I just did the following in the console:

const iti = window.intlTelInput.instances[0];
iti.setNumber("+17021231234");
document.querySelector("#phone").value = "123"
iti.setNumber("+447947123123");

After the first setNumber, the selected country correctly changes to US. Then after the 2nd setNumber, the selected country correctly changes to UK. So I don't understand the problem. Please can you provide steps to reproduce, being more specific about exactly what values to use to reproduce the issue.

@HKallaste
Copy link
Author

If the second number is missing the country code, there isn't a case for returning to the default. e.g.
iti.setNumber("7947123123");

@jackocnr
Copy link
Owner

As of the latest version, v23.0.12, you should be able to call setCountry() (passing no argument) to reset it to the globe icon. Let me know if you have any other issues.

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

No branches or pull requests

2 participants