Back

Example: Using the promise returned from initialisation

Use this promise to know when the plugin has completely finished initialising, including completing any asynchronous actions you might have enabled with the initialisation options e.g. fetching utils.js with the utilsScript option, and performing the ip lookup with the geoIpLookup option.

Markup

<!-- polyfill for IE11 -->
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.js"></script> 

<p>
  Status:
  <span id="status">Initialising...</span>
</p>
<input id="phone" type="tel">

Code

var input = document.querySelector("#phone");
var statusElement = document.querySelector("#status");

var iti = window.intlTelInput(input, {
  utilsScript: "../../build/js/utils.js?1549804213570",
});
iti.promise.then(function() {
  statusElement.innerHTML = "Initialised!";
});

Result

Status: Initialising...