Closed jackocnr closed 5 years ago
You want me to create a new pull request?
Thanks very much for reporting this bug and creating the codepen. Unfortunately I find the proposed solution to be too complicated, as this is an edge case IMO.
Can I ask: why do you need to initialise the plugin before you show the input? Wouldn't it be better to just initialise it after you show it?
I'm using JQuery Mobile and when a page is loaded by it through ajax, the content (including your plugin initialization) is first rendered before the page is actually shown. I'd have to listen for a pageshow
event every time I want to include a tel input and there is the possibility that the input would look off during the page transition.
Ok then I am open to a PR, but with a few changes:
.intl-tel-input
container and all of it's descendants (including the hundreds of countries in the list!), can we just do a shallow clone of the .intl-tel-input
container, and then inject into that a deep clone of the .selected-flag
element (I don't think we need to worry about the .flag-container
element). You can access the container with this.telInput.parentNode
- no need for a while loop there, and then with this implementation you will have direct access to the cloned selectedFlag element, so you wont have to query for that.Thanks very much.
body
element.the loop is required in cases where the input gets wrapped by another plugin
If you have other plugins that are manipulating the markup around the input then you should make sure those get run before you intialise this plugin else you will get styling problems as this plugin's container really needs to be the parent of the input element.
So I have merged your PR (thank you so much), but I have removed that loop code in a followup.
Originally posted by @crabnky in https://github.com/jackocnr/intl-tel-input/issues/885#issuecomment-487786957
Originally posted by @mac89 in https://github.com/jackocnr/intl-tel-input/issues/885#issuecomment-496980252
https://codepen.io/mac89/pen/gJJBLR
This issue is caused when the element is hidden when the plugin is initialized causing the
offsetWidth
to be 0.My proposed solution is this: