question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disable and remove autoFormat feature

See original GitHub issue

I have been back and forth about this a lot - I spent a lot of time implementing the autoFormat feature and fixing bugs, and I think it’s a super cool feature, BUT I think it’s time to disable and remove it for the following reasons:

  • First and foremost, we are hacking libphonenumber to get this to work, which is dangerous. It was not made for this purpose, they do not support our use case, and they have explicitly advised us against using it this way.
  • When the user types we have to call preventDefault so we can control what happens, but this means we lose a bunch of useful native events like change and input, which other devs may depend on.
  • Last time I checked, autoFormat didn’t work in Android Cordova apps, or in IE Mobile (see Browser Compatibility section of readme). Who knows what other browsers/versions/platforms make it not work properly.
  • There is no way around this incredibly counter-intuitive UX issue: https://github.com/jackocnr/intl-tel-input/issues/322 where you cannot type the first character from the placeholder. This affects 49 countries including the USA - see https://github.com/jackocnr/intl-tel-input/issues/346#issuecomment-183771143.
  • Another minor issue: even if we find a fix for the above issue, it will lead to a new one: when a country placeholder starts with a formatting char (e.g. US starts with an open bracket), if you press that char to try and start the number, you will get a red flash as that is not an accepted key, but then it will still add the char because autoFormat does a lookahead and adds any upcoming formatting chars on each keypress, which leads to a confusing experience.
  • Then there’s all the issues we have already come across, which suggests to me that there are so many more we don’t yet know about. We get bug reports for the popular countries, but much less for the unpopular ones, which means most likely they are buggy and we just don’t know about it.
  • Finally, restricting what the user can do in a regular <input> is considered bad practice by a lot of people (I have yet to find an example of Google or Facebook doing anything like this). As we have seen, this approach is very prone to bugs, and when there are bugs it can completely ruin the UX, or even render the whole input useless. It’s a very dangerous approach.

Notes

I’m open to discussion, but at this point I’m pretty convinced, and would welcome a pull request that implemented this change.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:68
  • Comments:38 (13 by maintainers)

github_iconTop GitHub Comments

28reactions
jackocnrcommented, Feb 11, 2016

Implemented this change in v8.0.0.

RIP autoFormat ❤️

12reactions
multiwebinccommented, Mar 5, 2020

Here’s the code @chatis provided above without jQuery since the library no longer requires it:

const telInput = document.querySelector("#telInput");

var iti = window.intlTelInput(telInput, {
      utilsScript: "/js/intl-tel-input/utils.js",
      preferredCountries: ['AU'],
      nationalMode: false,
      formatOnDisplay: true // SET THIS!!!
    }
);

telInput.addEventListener('keyup', formatIntlTelInput);
telInput.addEventListener('change', formatIntlTelInput);

function formatIntlTelInput() {
    if (typeof intlTelInputUtils !== 'undefined') { // utils are lazy loaded, so must check
        var currentText = iti.getNumber(intlTelInputUtils.numberFormat.E164);
        if (typeof currentText === 'string') { // sometimes the currentText is an object :)
            iti.setNumber(currentText); // will autoformat because of formatOnDisplay=true
        }
    }
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to enable and disable Microsoft Word AutoFormat feature
Open Microsoft Word. In the menu bar, click Format and select AutoFormat. Click the Options button. In this section, users can enable or...
Read more >
How to Disable Microsoft Word AutoFormat Feature - YouTube
Hey! Welcome to HOWZA channel! In today's lesson, you will learn how to disable Microsoft Word AutoFormat Feature.To enable or disable the ...
Read more >
disable Microsoft Word AutoFormat feature - YouTube
Microsoft Word: How to Stop Annoying Automation; How to Turn Off Automatic Changes in Microsoft Word. Dawn Bjork-The Software Pro.
Read more >
How to turn off the AutoCorrect and AutoFormat features in Visio
On the Tools menu, click AutoCorrect Options. · Click the AutoCorrect tab. · Click to clear the check boxes of the rules that...
Read more >
Turn Off AutoFormat in Mac Word
Turn Off AutoFormat in Mac Word · Click on Word and then Preferences. Step 1 · On the AutoFormat as You Type tab...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found