0

I using intlTelInput for the telephone & mobile field on asp.net webform website.

At present i am using it as a basic plugin as show in this example

var input = $("#ContentPlaceHolder1_txtPhone"), output = $("#output");
            var country = $("#ContentPlaceHolder1_ddCountry");

            input.intlTelInput({
                preferredCountries: ['ae'],
                autoHideDialCode: true,
                nationalMode: false,
                utilsScript: "../../Scripts/phone/js/utils.js" // just for formatting/placeholders etc
            });

Now i am trying to sync it with the Country drop-down so that when user select the country it then automatically select the Telephone Fields & Mobile field on web-form with the country in telephone fields.

I tried to use this example but it is not working either it break the plugin or it downt work

http://intl-tel-input.com/node_modules/intl-tel-input/examples/gen/country-sync.html

Code which i tried

var countryData = $.fn.intlTelInput.getCountryData(),
                telInput = $("#ContentPlaceHolder1_txtPhone"),
                addressDropdown = $("#ContentPlaceHolder1_ddCountry");

            // set it's initial value
            //var initialCountry = telInput.intlTelInput("getSelectedCountryData").iso2;
            //addressDropdown.val(initialCountry);
            // listen to the telephone input for changes
            telInput.on("countrychange", function (e, countryData) {
                addressDropdown.val(countryData.iso2);
            });
            // listen to the address dropdown for changes
            addressDropdown.change(function () {
                telInput.intlTelInput("setCountry", $(this).val());
            });

I have place code on codepen http://codepen.io/anon/pen/wgzppg.

I am not sure where i am doing it wrong. i tried few thing without any luck.

I pull data for country dropdown from database table not the plugin so that may be causing issue somewhere. but country code are matching also.

Learning
  • 19,469
  • 39
  • 180
  • 373

1 Answers1

0

I solved it problem seems to be with the countryCode as was getting countryCode in UpperCase and changing that to lower case seemed to have fixed the issue

working sample http://codepen.io/anon/pen/BpLJEZ?editors=1010

<div class="col-xs-12 col-sm-12 col-md-6">
  <label class="cf-label">Country*</label>
  <select name="ctl00$ContentPlaceHolder1$ddCountry" id="ContentPlaceHolder1_ddCountry" class="form-control ddCountry styled-select">
    <option value="af">Afghanistan</option>
    <option value="ax">Ă…land Islands</option>
    <option value="al">Albania</option>
    <option value="dz">Algeria</option>
    <option value="as">American Samoa</option>
    <option value="ad">Andorra</option>
    <option value="ao">Angola</option>
    <option value="ai">Anguilla</option>
    <option value="aq">Antarctica</option>
    <option value="ag">Antigua And Barbuda</option>
    <option value="ar">Argentina</option>
    <option value="am">Armenia</option>
    <option value="aw">Aruba</option>
    <option value="au">Australia</option>
    <option value="at">Austria</option>
    <option value="az">Azerbaijan</option>
    <option value="bs">Bahamas</option>
    <option value="bh">Bahrain</option>
    <option value="bd">Bangladesh</option>
</select>
  <span data-val-controltovalidate="ContentPlaceHolder1_ddCountry" data-val-errormessage="*" data-val-display="Dynamic" data-val-validationgroup="vgDonationtForm" id="ContentPlaceHolder1_rfCountry" class="CssValidator" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid"
    data-val-initialvalue="-- Select --" style="display:none;">*</span>
</div>

<div class="col-xs-12 col-sm-12 col-md-6">
  <label class="label">Mobile Number *</label>
<input name="ctl00$ContentPlaceHolder1$txtPhone" id="ContentPlaceHolder1_txtPhone" class="rg-txt rg-phone-txt form-control cf-input" autocomplete="off" placeholder="+971 50 123 4567" type="text">
</div>
Learning
  • 19,469
  • 39
  • 180
  • 373