I just can not understand what's the matter. There are 2 text fields in the template.
<input type="text" id="first"> <input type="text" id="second"> They are designed for phones. You need to make a mask and the ability to select a code. To do this, use jQuery and 2 plugins to it:
- intl-tel-input ( https://github.com/jackocnr/intl-tel-input )
- jQuery-Mask-Plugin ( https://github.com/igorescobar/jQuery-Mask-Plugin )
Wrote the initialization code for these two fields.
function initPhoneMask(fieldId) { // ΠΈΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·ΠΈΡΡΠ΅ΠΌ ΠΏΠΎΠ»Π΅ Π΄Π»Ρ ΡΠ΅Π»Π΅ΡΠΎΠ½Π° // https://github.com/jackocnr/intl-tel-input $(fieldId).intlTelInput({ autoHideDialCode: false, nationalMode: false, preferredCountries: ['ru'], utilsScript: "utils.js" }); // ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ ΠΏΡΠΈ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΈ ΡΠ΅Π»Π΅ΡΠΎΠ½Π½ΠΎΠ³ΠΎ ΠΊΠΎΠ΄Π° $(fieldId).on("countrychange", function(e, countryData) { if (countryData.iso2 === "ru") { $(this).mask('+7 (000) 000-00-00'); } else { $(this).unmask(); } }); // ΠΈΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·ΠΈΡΡΠ΅ΠΌ ΠΌΠ°ΡΠΊΡ Π΄Π»Ρ ΡΠ΅Π»Π΅ΡΠΎΠ½Π° // https://github.com/igorescobar/jQuery-Mask-Plugin $(fieldId).mask('+7 (000) 000-00-00'); } $(document).ready(function() { initPhoneMask("#first"); initPhoneMask("#second"); }); That is, the string
$(fieldId).mask('+7 (000) 000-00-00'); initializes the field with the initially desired mask, and the handler hangs / unmasks the mask if the code of the desired country is selected / not selected.
BUT. When changing the country code, to any other mask does not disappear. If you remove the initialization code, then everything works, but at first the field is not initialized by the mask.
Why is that? MB someone came across?