简体   繁体   English

如何用电话号码保存国家代码?

[英]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.

相关问题 如何区分国家/地区代码形式的电话号码? - How to separate country code form Phone number? 如何分别获取国家代码和电话号码并根据javascript中的国家代码验证ph号码的长度? - How to get country code and phone number separately and validate length of the ph number based on country code in javascript? 如何使用正则表达式使用国家/地区代码格式化手机号码 - How to format mobile phone number with country code using regex 如何使用正则表达式验证电话号码中的国家/地区代码 - How to make regex that validate country code in phone number 为电话号码选择国家/地区代码时,如何将土耳其设为默认国家/地区? - How can I make Turkey the default country when choosing a country code for a phone number? 根据国家/地区代码验证电话号码 - Validating Phone Number based on country code 使用 intlTelInput 验证带有国家代码的电话号码 - Validation phone number with country code using intlTelInput 验证电话号码和国家/地区代码组合以验证Angular 4中的电话号码吗? - Validate Phone Number and Country Code combination for phone number validition in Angular 4? 检测 react-native-phone-number 的国家/地区代码 - Detecting country code for react-native-phone-number 从电话号码 vue-tel-input 中删除国家代码 - Remove country code from phone number vue-tel-input
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM