[英]International Telephone Input with Country sync for plugin not working
I using intlTelInput for the telephone & mobile field on asp.net webform website. 我在asp.net Webform网站的电话和移动领域使用intlTelInput 。
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. 现在,我尝试将其与“国家/地区”下拉列表同步,以便当用户选择国家/地区时,它会自动在Web表单上选择“电话字段和移动”字段,并在电话字段中选择国家/地区。
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 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 . 我在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.
但是国家代码也匹配。
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 我解决了问题,似乎与countryCode有关,就像在UpperCase中获取countryCode一样,并将其更改为小写似乎已解决了该问题
working sample http://codepen.io/anon/pen/BpLJEZ?editors=1010 工作样本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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.