I want to format both phone and credit card input using cleave.js (in rails). I've got the formatting working if I only declare one new Cleave
object, but I get this error if I attempt to declare two:
Uncaught Error: [cleave.js] Please check the element
Here's the relevant parts of the JS file:
var Global = {};
Global.onLoad = function(){
Global.setupDatepickers(); //unrelated function
Global.setupCleavePhone();
Global.setupCleaveCreditCard();
};
$(document).on('turbolinks:load', function(){
Global.onLoad();
});
Global.setupCleavePhone = function() {
new Cleave('.phone-input', {
phone: true,
phoneRegionCode: 'US',
delimiter: '-'
});
}
Global.setupCleaveCreditCard = function() {
new Cleave('.card-input', {
delimiter: '-',
blocks: [4,4,4,4]
});
}
I've tried a few remixes of this including assigning the Cleave objects to variables and declaring them in the same function, but no dice. Here's a jsfiddle of multiple cleave objects being delared at once, and I can't see any meaningful differences between my code and theirs. The selector classes are properly applied in the view. Any thoughts why I can't seem to format two fields at once?