AutorÃa | Ultima modificación | Ver Log |
// get the country data from the pluginvar countryData = window.intlTelInputGlobals.getCountryData(),input = document.querySelector("#phone"),addressDropdown = document.querySelector("#address-country");// init pluginvar iti = window.intlTelInput(input, {utilsScript: "../../build/js/utils.js?<%= time %>" // just for formatting/placeholders etc});// populate the country dropdownfor (var i = 0; i < countryData.length; i++) {var country = countryData[i];var optionNode = document.createElement("option");optionNode.value = country.iso2;var textNode = document.createTextNode(country.name);optionNode.appendChild(textNode);addressDropdown.appendChild(optionNode);}// set it's initial valueaddressDropdown.value = iti.getSelectedCountryData().iso2;// listen to the telephone input for changesinput.addEventListener('countrychange', function(e) {addressDropdown.value = iti.getSelectedCountryData().iso2;});// listen to the address dropdown for changesaddressDropdown.addEventListener('change', function() {iti.setCountry(this.value);});