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 doesn't work #701

Closed
sinneren opened this issue Feb 27, 2018 · 11 comments
Closed

formatting doesn't work #701

sinneren opened this issue Feb 27, 2018 · 11 comments

Comments

@sinneren
Copy link

Hello. I'm using all of examples, and formatting number is not work. Only when i download another utils.js it's work fine with input.val(input.intlTelInput("getNumber");
Another utils from demo's: http://formvalidation.io/examples/validating-international-phone-numbers/

And when i tried to add unformatted it still formatted. input_hidden.val(input.intlTelInput("getNumber", intlTelInputUtils.numberFormat.E164). It doesn't work with any numberFormat.
Always return some like "+7 963 555-55-55". But I need without symbols and country code.

@jackocnr
Copy link
Owner

Hi, please can you be specific about what your use case - exactly when do you want the number to be formatted?

If it's when you init the plugin with an existing number in the input, then that's controlled by formatOnDisplay option.

We have completely removed the format-as-you-type functionality.

@sinneren sinneren changed the title formatting doesn't wokr formatting doesn't work Feb 28, 2018
@sinneren
Copy link
Author

sinneren commented Feb 28, 2018

You meen that formatting when typing and pasting is removed from plugin? I need some. It's not working with or without formatOnDisplay option. It's about first part.
About second:

        this._phoneNumberTextbox.on('keyup change', this, function (event) {
             var instance = event.data;
             instance._phoneNumberTextbox.intlTelInput("setNumber", instance._phoneNumberTextbox.intlTelInput("getNumber")); // +7 999 999 99-99
             
             var intlNumber = instance._phoneNumberTextbox.intlTelInput("getNumber", intlTelInputUtils.numberFormat.NATIONAL);
             console.log(intlNumber); // +7 999 999 99-99

Here, intlNumber variable still have full formatted number +7 999 999 99-99, but national must be only 9999999999, right? And it's always in +7 999 999 99-99 format with any type numberFormat.

My init code:

this._phoneNumberTextbox.intlTelInput({
        initialCountry: "auto",
        autoPlaceholder: true,
        autoHideDialCode: true,
        formatOnDisplay: true,
        nationalMode: true,
        utilsScript: "/vendor/js/utils.js",
        geoIpLookup: function (callback) {
            $.get('https://ipinfo.io', function () { }, "jsonp").always(function (resp) {
                var countryCode = (resp && resp.country) ? resp.country : "";
                callback(countryCode);
            });
        }
    });

@jackocnr
Copy link
Owner

You meen that formatting when typing and pasting is removed from plugin?

Yes. We mention this in the template when you create a new issue here on Github (and there's a link to more info).

As for using getNumber and specifying a format - are you testing this with a valid number? This method only works on valid numbers, as per the readme.

@sinneren
Copy link
Author

sinneren commented Mar 1, 2018

As for using getNumber and specifying a format - are you testing this with a valid number? This method only works on valid numbers, as per the readme.

Yes, it's about valid number. I'm using external libphonenumber.js (fork of google) for formatting to national mode.

@jackocnr
Copy link
Owner

jackocnr commented Mar 1, 2018

I'm using external libphonenumber.js (fork of google) for formatting to national mode.

I'm afraid I can only offer support for the utils.js provided by this plugin. If you're having problems with another lib, you'll have to open an issue with them.

I have just double checked, and you can indeed extract just the national number using the provided utils.js. If you go to the demo site, enter a valid number, open dev tools and type $('#phone').intlTelInput('getNumber', intlTelInputUtils.numberFormat.NATIONAL) you will see it returns just the national number (formatted). If you want it without formatting, you would then have to strip all non-numeric characters.

@sinneren
Copy link
Author

sinneren commented Mar 2, 2018

Ok, thank you. Just one last question. How to rebuild your utils.js?
I think, that intlTelInputUtils.numberFormat.NATIONAL is not working for me, because I use old version if util.js. Now, I download latest and revert for me formatAsYouType in src/js/utils.js. And start build:js. Rebuilding is successfull, but only for plugin, utils.js in build is still the same.

@jackocnr
Copy link
Owner

jackocnr commented Mar 2, 2018

There are instructions at the top of src/js/utils.js on how to re-build it.

But as I said, the plugin no longer supports format-as-you-type, so even if you re-add that code in utils.js and re-build it, that feature will still not work as the code has been removed from src/js/intlTelInput.js. For more info on why we removed it, see this thread: #346

@kiwina
Copy link

kiwina commented Jul 14, 2018

even the demo does not return
intlTelInputUtils.numberFormat.NATIONAL

@jackocnr
Copy link
Owner

It works for me. If I go to intl-tel-input.com, open devtools console and type intlTelInputUtils.numberFormat.NATIONAL and hit enter, it correctly returns 2.

@walkwel-tech
Copy link

walkwel-tech commented Feb 11, 2019

facing the same issue. Any workaround?

@salmanbangash1176
Copy link

The full_phone is gonna do the trick.It will append a hidden field with full number when submitting the form

    var input = document.querySelector("#phone");
    window.intlTelInput(input, {
    hiddenInput: "full_phone",
    utilsScript: "../../build/js/utils.js" 
    });

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

5 participants