cleave.js
cleave.js copied to clipboard
Cannot read property 'inputType' of undefined
I get this error: Uncaught TypeError: Cannot read property 'inputType' of undefined at i.onChange (cleave.min.js:8) at i.setPhoneRegionCode (cleave.min.js:8)
anytime I try to use any function of the cleave instance!!!
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.
Same issue
This is working in my case: Just changing the prop without using setPhoneRegionCode
select.addEventListener('change', function(){ cleave.phoneRegionCode = this.value; cleave.setRawValue(''); })
Hope it helps!
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.