Inconsistent behaviour
I am trying to use getNumber but it is only working on the initial call. To reproduce:
- go to https://intl-tel-input.com/examples/strict-mode.html
- enter phone code in international format
- Run
intlTelInput(document.getElementById('phone')).getNumber(intlTelInput.utils.numberFormat.E164)in the console. It returns correctly however the displayed value in the input changes. - Run command again. It returns national phone number.
In addition intlTelInput(document.getElementById('phone')).getValidationError(); will then give 1 as an error after executing getNumber().
When you run intlTelInput(document.getElementById('phone')).getNumber(intlTelInput.utils.numberFormat.E164) you are initialising the plugin on an input where the plugin is already initialised - you shouldn't do this. Instead you should be using the instance variable to run getNumber. In your own code, this would be:
const iti = intlTelInput(input);
iti.getNumber();
But if you want to do something similar on the demo site, you don't have direct access to the instance variable, so instead you can find it with something like this:
const iti = intlTelInput.instances[0];
iti.getNumber();
Thanks for the explanation!