jackocnr / intl-tel-input

A JavaScript plugin for entering and validating international telephone numbers
https://intl-tel-input.com
MIT License
7.54k stars 1.94k forks source link

Everytime I input +xxx it converts back to 0 or removes +xxx numbers #1698

Closed stefann4 closed 1 month ago

stefann4 commented 1 month ago

Plugin version

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

Steps to reproduce

  1. This is my example of an input image

Expected behaviour

Since this is correct input for particular country, It should leave value like this.

Actual behaviour

Instead, everytime I leave this input tag (I'm using (blur) event in Angular) it changes value to this: image

This happens no matter what configuration put in my .ts file , this is my current configuration: this.input = (<HTMLInputElement>document.getElementById("phone")); intlTelInput(this.input, { utilsScript: "https://cdn.jsdelivr.net/npm/intl-tel-input@23.3.2/build/js/utils.js", allowDropdown: true, nationalMode: true }); -I have tried with nationalMode: false too.

Initialisation options

List any options you're using e.g. utilsScript or onlyCountries

jackocnr commented 1 month ago

The plugin doesn't do anything on blur - this must be your own code that is changing the input value on blur.

stefann4 commented 1 month ago

It is not my code, blur is just event where I am checking weather phone number is valid or not. Rest of it is just pure configuration of this plugin.

пет, 12. јул 2024. у 10:34 jackocnr @.***> је написао/ла:

The plugin doesn't do anything on blur - this must be your own code that is changing the input value on blur.

— Reply to this email directly, view it on GitHub https://github.com/jackocnr/intl-tel-input/issues/1698#issuecomment-2225091450, or unsubscribe https://github.com/notifications/unsubscribe-auth/AV3ZYT6HM2XD7L22NCZMVJDZL6IIBAVCNFSM6AAAAABKX3PGM6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRVGA4TCNBVGA . You are receiving this because you authored the thread.Message ID: @.***>

jackocnr commented 1 month ago

I'm really confused. Can you please give clear steps to reproduce the problem. Give as much detail as possible.

stefann4 commented 1 month ago

Sure,

I'm using angular. I have installed needed package with npm command. This is the configuration inside my .ts file: ngAfterViewInit(): void { this.input = (document.getElementById("phone")); intlTelInput(this.input, { initialCountry: "auto", geoIpLookup: function(success, failure) { fetch("https://ipapi.co/json") .then(function(res) { return res.json(); }) .then(function(data) { success(data.country_code); }) .catch(function() { failure(); }); }, utilsScript: @.***/build/js/utils.js", nationalMode: false }); }

This is my .html file connected with .ts file


Format phone number is not correct.
</div>

When I try to manually input +381, after I occur event the +381 value converts to 0 manually. For example; If I input +381 123 123 1 it automatically changes to 01231231 and it doesn't give any information inside iti.getSelectedCountryData() with this format of 0.

суб, 13. јул 2024. у 00:49 jackocnr @.***> је написао/ла:

Reopened #1698.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

jackocnr commented 1 month ago

So to be clear, you initialise the plugin, you focus the input and type +381 and then you don't do anything else, the number just immediately changes on its own?

stefann4 commented 1 month ago

Correct.

On Sat, 13 Jul 2024 at 20:04, jackocnr @.***> wrote:

So to be clear, you initialise the plugin, you focus the input and type +381 and then you don't do anything else, the number just immediately changes on its own?

— Reply to this email directly, view it on GitHub https://github.com/jackocnr/intl-tel-input/issues/1698#issuecomment-2227034035, or unsubscribe https://github.com/notifications/unsubscribe-auth/AV3ZYT74DZEZ2Z7DWLCJRG3ZMFT25AVCNFSM6AAAAABKX3PGM6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRXGAZTIMBTGU . You are receiving this because you authored the thread.Message ID: @.***>

stefann4 commented 1 month ago

Actually, when I occur submit button, it automatically changes.

On Sat, 13 Jul 2024 at 20:54, stefan nikolic @.***> wrote:

Correct.

On Sat, 13 Jul 2024 at 20:04, jackocnr @.***> wrote:

So to be clear, you initialise the plugin, you focus the input and type +381 and then you don't do anything else, the number just immediately changes on its own?

— Reply to this email directly, view it on GitHub https://github.com/jackocnr/intl-tel-input/issues/1698#issuecomment-2227034035, or unsubscribe https://github.com/notifications/unsubscribe-auth/AV3ZYT74DZEZ2Z7DWLCJRG3ZMFT25AVCNFSM6AAAAABKX3PGM6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRXGAZTIMBTGU . You are receiving this because you authored the thread.Message ID: @.***>

jackocnr commented 1 month ago

Ah ok, so it's when you click the submit button. So what does your code do on submit? Does it reload the page?

stefann4 commented 1 month ago

Not really, all it does it calls a function which contains intl.getNumber() and after that it's http request not referred to your plugin

On Sat, 13 Jul 2024 at 23:29, jackocnr @.***> wrote:

Ah ok, so it's when you click the submit button. So what does your code do on submit? Does it reload the page?

— Reply to this email directly, view it on GitHub https://github.com/jackocnr/intl-tel-input/issues/1698#issuecomment-2227107718, or unsubscribe https://github.com/notifications/unsubscribe-auth/AV3ZYTYCIT4MWPBEVRFBDDTZMGL3RAVCNFSM6AAAAABKX3PGM6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRXGEYDONZRHA . You are receiving this because you authored the thread.Message ID: @.***>

jackocnr commented 1 month ago

all it does it calls a function which contains intl.getNumber()

Well getNumber doesn't change the input value, so it's not that.

and after that it's http request not referred to your plugin

I don't understand this bit. Does the page reload? Do you navigate to another page which uses the plugin?

Can you share your submit handler code?

jackocnr commented 1 month ago

Closing due to inactivity.