cleave.js icon indicating copy to clipboard operation
cleave.js copied to clipboard

cleave.min.js:8 Uncaught TypeError: Cannot read property 'inputType' of undefined

Open harontaiko opened this issue 4 years ago • 6 comments

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();
  });

harontaiko avatar Jul 12 '20 17:07 harontaiko

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.

graham-saunders avatar Jul 30 '20 19:07 graham-saunders

what's the solution?

harontaiko avatar Jul 31 '20 09:07 harontaiko

@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

graham-saunders avatar Jul 31 '20 15:07 graham-saunders

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.

hayden664 avatar Dec 01 '20 03:12 hayden664

Use the previous build(v1.5.10). The current is broken.

WebDevMaster2016 avatar Aug 23 '21 18:08 WebDevMaster2016

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.

davidenco avatar Jan 14 '22 15:01 davidenco