[英]How to save country code with phone number?
How do I initialize utilsScript
?如何初始化
utilsScript
?
In the intl-tel-input gem documentation it says...在intl-tel-input gem 文档中,它说...
Recommended : initialize the plugin with the utilsScript option to enable formatting/validation, and to allow you to extract full international numbers using getNumber.
推荐:使用 utilsScript 选项初始化插件以启用格式化/验证,并允许您使用 getNumber 提取完整的国际号码。
I want to initialize the plugin because I want to use getNumber
.我想初始化插件,因为我想使用
getNumber
。
<%= telephone_field_tag :number, nil, placeholder: 'Enter Phone Number', class: 'form-control', id: "country" %>
<script>
$("#country").intlTelInput({
separateDialCode: true
});
$("form").submit(function() {
myInput.val(myInput.intlTelInput("getNumber")); // Without getNumber the international code doesn't save in the parameters
});
</script>
I'm also using intl-tel-input-rails gem to package the intl-tel-input assets (JavaScripts, stylesheets, and images) for the Rails asset pipeline.我还使用intl-tel-input-rails gem为 Rails 资产管道打包intl-tel-input资产(JavaScript、样式表和图像)。
My current script triggers this error...我当前的脚本触发了这个错误...
Uncaught ReferenceError: myInput is not defined
I switched gems...我换了宝石...
https://github.com/ispyropoulos/intl-tel-input-rails https://github.com/ispyropoulos/intl-tel-input-rails
because this I can include the line //= require libphonenumber/utils
.因为这我可以包括行
//= require libphonenumber/utils
。
And in the script I adjusted to...在脚本中我调整为...
$("form").submit(function() {
$('#country').val($('#country').intlTelInput("getNumber"));
});
And I also needed to use text_field
而且我还需要使用
text_field
include包括
<script src="assets/plugins/build/js/utils.js"></script>
then call var number = $("#phone").intlTelInput("getNumber");
然后调用
var number = $("#phone").intlTelInput("getNumber");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.