[英]How to mask inputs using cocoon gem?
So, I have an javascript like this:所以,我有一个这样的javascript:
$(document).on("turbolinks:load", function() {
$('#client_phone').mask('(00)00000-0000');
});
It works only for the first element, when I click on "add new fields", the mask doesn't apply.它仅适用于第一个元素,当我单击“添加新字段”时,掩码不适用。 So I tried using cocoon callbacks, like this:
所以我尝试使用 cocoon 回调,如下所示:
$(document).on('turbolinks:load', function() {
$('#phone_clients').on('cocoon:after-insert', function() {
$('#client_phone').mask('(00)00000-0000');
});
});
But it doesn't work, I have tested using alert('something') inside the callback and it has appeared.但它不起作用,我在回调中使用 alert('something') 进行了测试,它已经出现了。 So I have no idea why the mask isn't applying.
所以我不知道为什么面膜不适用。
Could you guys, please, help me?请你们帮帮我好吗?
Try the below:试试下面的:
$(document).on('turbolinks:load', function() {
$('#phone_clients').on('cocoon:after-insert', function(e, insertedItem) {
$(insertedItem).find('#client_phone').mask('(00)00000-0000');
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.