简体   繁体   中英

not getting Country code from intlTelInput input

In my Laravel project, I am using intlTelInput for getting the country code input field. I am getting the country code and country flags (readonly). But when I submit form I am getting only the text field value but not getting the country code merging with it. like I select Bangladesh. the beside the flag is shows- 880 in the read-only field. after that then I put the rest of the number in the editable text field like: 171111111 and submit the result I am getting is 17111111. I am not getting the country code merged result like 8801711111111. What to do?

blade.php part:

<input id="phone" class="form-control" name="client_phone1" type="tel" />

script part:

<script>
  var input = document.querySelector("#phone");
  window.intlTelInput(input, {
    // allowDropdown: false,
    // autoHideDialCode: false,
    autoPlaceholder: "off",
    // dropdownContainer: document.body,
    // excludeCountries: ["us"],
    // formatOnDisplay: false,
    // geoIpLookup: function(callback) {
    //   $.get("http://ipinfo.io", function() {}, "jsonp").always(function(resp) {
    //     var countryCode = (resp && resp.country) ? resp.country : "";
    //     callback(countryCode);
    //   });
    // },
    // hiddenInput: "full_number",
    // initialCountry: "auto",
    // localizedCountries: { 'de': 'Deutschland' },
    // nationalMode: false,
    // onlyCountries: ['us', 'gb', 'ch', 'ca', 'do'],
    placeholderNumberType: "MOBILE",
    preferredCountries: ["bd"],
    separateDialCode: true,
    utilsScript: "public/build/js/utils.js"
  });
</script>

add in variable

var iti= window.intlTelInput(input, {
    // allowDropdown: false,
    // autoHideDialCode: false,
    autoPlaceholder: "off",
    // dropdownContainer: document.body,
    // excludeCountries: ["us"],
    // formatOnDisplay: false,
    // geoIpLookup: function(callback) {
    //   $.get("http://ipinfo.io", function() {}, "jsonp").always(function(resp) {
    //     var countryCode = (resp && resp.country) ? resp.country : "";
    //     callback(countryCode);
    //   });
    // },
    // hiddenInput: "full_number",
    // initialCountry: "auto",
    // localizedCountries: { 'de': 'Deutschland' },
    // nationalMode: false,
    // onlyCountries: ['us', 'gb', 'ch', 'ca', 'do'],
    placeholderNumberType: "MOBILE",
    preferredCountries: ["bd"],
    separateDialCode: true,
    utilsScript: "public/build/js/utils.js"
  });

get like this

iti.getSelectedCountryData().iso2,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM