From c137bc28d1c0296c227ad661f43a794f174ef703 Mon Sep 17 00:00:00 2001 From: EugeneSnihovsky Date: Fri, 23 Oct 2015 16:56:01 +0300 Subject: [PATCH] fix for choose country code after async data received --- releases/international-phone-number.js | 3 +++ releases/international-phone-number.min.js | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/releases/international-phone-number.js b/releases/international-phone-number.js index 56a6ec0..b68bf13 100644 --- a/releases/international-phone-number.js +++ b/releases/international-phone-number.js @@ -59,6 +59,9 @@ } }); watchOnce = scope.$watch('ngModel', function(newValue) { + if(!newValue) { // wait for async data received and only then do logic below and unwatch + return; + } return scope.$$postDigest(function() { if (newValue !== null && newValue !== void 0 && newValue.length > 0) { if (newValue[0] !== '+') { diff --git a/releases/international-phone-number.min.js b/releases/international-phone-number.min.js index 665e166..c110ef8 100644 --- a/releases/international-phone-number.min.js +++ b/releases/international-phone-number.min.js @@ -1,2 +1,2 @@ -/*! international-phone-number 2015-09-17 */ -(function(){"use strict";angular.module("internationalPhoneNumber",[]).constant("ipnConfig",{allowExtensions:!1,autoFormat:!0,autoHideDialCode:!0,autoPlaceholder:!0,customPlaceholder:null,defaultCountry:"",geoIpLookup:null,nationalMode:!0,numberType:"MOBILE",onlyCountries:void 0,preferredCountries:["us","gb"],utilsScript:""}).directive("internationalPhoneNumber",["$timeout","ipnConfig",function(a,b){return{restrict:"A",require:"^ngModel",scope:{ngModel:"="},link:function(c,d,e,f){var g,h,i,j;return f&&""!==d.val()&&a(function(){return d.intlTelInput("setNumber",d.val()),f.$setViewValue(d.val())},0),i=function(){return f.$setViewValue(d.val())},g=function(a){return a instanceof Array?a:a.toString().replace(/[ ]/g,"").split(",")},h=angular.copy(b),angular.forEach(h,function(a,b){var c;if(e.hasOwnProperty(b)&&angular.isDefined(e[b]))return c=e[b],"preferredCountries"===b?h.preferredCountries=g(c):"onlyCountries"===b?h.onlyCountries=g(c):"boolean"==typeof a?h[b]="true"===c:h[b]=c}),j=c.$watch("ngModel",function(a){return c.$$postDigest(function(){return null!==a&&void 0!==a&&a.length>0&&("+"!==a[0]&&(a="+"+a),d.val(a)),d.intlTelInput(h),void 0!==e.skipUtilScriptDownload||h.utilsScript||d.intlTelInput("loadUtils","/bower_components/intl-tel-input/lib/libphonenumber/build/utils.js"),j()})}),f.$formatters.push(function(a){return a?(d.intlTelInput("setNumber",a),d.val()):a}),f.$parsers.push(function(a){return a?a.replace(/[^\d]/g,""):a}),f.$validators.internationalPhoneNumber=function(a){var b;return b=d.intlTelInput("getSelectedCountryData"),!a||b&&b.dialCode===a?!0:d.intlTelInput("isValidNumber")},d.on("blur keyup change",function(a){return c.$apply(i)}),d.on("$destroy",function(){return d.intlTelInput("destroy"),d.off("blur keyup change")})}}}])}).call(this); \ No newline at end of file +/*! international-phone-number 2015-10-23 */ +(function(){"use strict";angular.module("internationalPhoneNumber",[]).constant("ipnConfig",{allowExtensions:!1,autoFormat:!0,autoHideDialCode:!0,autoPlaceholder:!0,customPlaceholder:null,defaultCountry:"",geoIpLookup:null,nationalMode:!0,numberType:"MOBILE",onlyCountries:void 0,preferredCountries:["us","gb"],utilsScript:""}).directive("internationalPhoneNumber",["$timeout","ipnConfig",function(n,e){return{restrict:"A",require:"^ngModel",scope:{ngModel:"="},link:function(t,r,o,u){var i,l,a,s;return u&&""!==r.val()&&n(function(){return r.intlTelInput("setNumber",r.val()),u.$setViewValue(r.val())},0),a=function(){return u.$setViewValue(r.val())},i=function(n){return n instanceof Array?n:n.toString().replace(/[ ]/g,"").split(",")},l=angular.copy(e),angular.forEach(l,function(n,e){var t;if(o.hasOwnProperty(e)&&angular.isDefined(o[e]))return t=o[e],"preferredCountries"===e?l.preferredCountries=i(t):"onlyCountries"===e?l.onlyCountries=i(t):l[e]="boolean"==typeof n?"true"===t:t}),s=t.$watch("ngModel",function(n){return n?t.$$postDigest(function(){return null!==n&&void 0!==n&&n.length>0&&("+"!==n[0]&&(n="+"+n),r.val(n)),r.intlTelInput(l),void 0!==o.skipUtilScriptDownload||l.utilsScript||r.intlTelInput("loadUtils","/bower_components/intl-tel-input/lib/libphonenumber/build/utils.js"),s()}):void 0}),u.$formatters.push(function(n){return n?(r.intlTelInput("setNumber",n),r.val()):n}),u.$parsers.push(function(n){return n?n.replace(/[^\d]/g,""):n}),u.$validators.internationalPhoneNumber=function(n){var e;return e=r.intlTelInput("getSelectedCountryData"),!n||e&&e.dialCode===n?!0:r.intlTelInput("isValidNumber")},r.on("blur keyup change",function(){return t.$apply(a)}),r.on("$destroy",function(){return r.intlTelInput("destroy"),r.off("blur keyup change")})}}}])}).call(this); \ No newline at end of file