cleave.js
cleave.js copied to clipboard
cleave.min.js:8 Uncaught TypeError: Cannot read property 'inputType' of undefined
this code returns an error once i select a new country code, the same error is also here https://jsfiddle.net/nosir/0amruddk/ i've tried nearly everything,
var selectCountry = $(".select-country"); var html = "";
for (var i in code) {
html += '<option value="+' + code[i] + '">' + i + "</option>";
}
selectCountry.html(html);
var cleavePhone = new Cleave(".input-phone", {
phone: true,
phoneRegionCode: "KE",
});
selectCountry.on("change", function () {
cleavePhone.setPhoneRegionCode(this.value);
cleavePhone.setRawValue(this.value);
$(".input-phone").focus();
});
I'm also seeing this issue --
Uncaught TypeError: Cannot read property 'inputType' of undefined at i.onChange (cleave.min.js:formatted:126) at i.setPhoneRegionCode (cleave.min.js:formatted:225) at HTMLSelectElement.
The problem is that onChange: function(e) {} uses e.inputType but when changing the phone region code, it calls onChange() without passing an event.
what's the solution?
@harontaiko the only solution we've seen is to use the all-country js so it auto formats the country as you type based on country code. Switching between countries will be broken until the above bug is fixed
I am having the same issue. May I know where do you find the all-country js? I am currently already using the cleave-phone.i18n.js, not sure if this is the one that you were talking about.
Use the previous build(v1.5.10). The current is broken.
In the cleave.min.js file in v1.6.0, locate and change this code:
t.isBackward=t.isBackward||"deleteContentBackward"===e.inputType;
To:
t.isBackward=t.isBackward||(typeof e!=="undefined"&&"deleteContentBackward"===e.inputType);
In my case, "e" is actually undefined. By introducing the typeof check, the "setPhoneRegionCode" method works as expected.