diff --git a/releases/international-phone-number.js b/releases/international-phone-number.js index c6b5f06..b1800df 100644 --- a/releases/international-phone-number.js +++ b/releases/international-phone-number.js @@ -72,12 +72,9 @@ ctrl.$formatters.push(function(value) { if (!value) { return value; - } else { - $timeout(function() { - return element.intlTelInput('setNumber', value); - }, 0); - return element.val(); } + element.intlTelInput('setNumber', value); + return element.val(); }); ctrl.$parsers.push(function(value) { if (!value) { @@ -86,23 +83,10 @@ return value.replace(/[^\d]/g, ''); }); ctrl.$validators.internationalPhoneNumber = function(value) { - if (element.attr('required')) { - if (!value) { - return false; - } else { - return element.intlTelInput("isValidNumber"); - } - } else { - if (element.intlTelInput("getSelectedCountryData").dialCode === value) { - return true; - } else { - if (!value) { - return true; - } else { - return element.intlTelInput("isValidNumber"); - } - } + if (!value) { + return true; } + return element.intlTelInput("isValidNumber"); }; element.on('blur keyup change', function(event) { return scope.$apply(read); diff --git a/releases/international-phone-number.min.js b/releases/international-phone-number.min.js index 28e2859..c07c305 100644 --- a/releases/international-phone-number.min.js +++ b/releases/international-phone-number.min.js @@ -1,2 +1,2 @@ -/*! international-phone-number 2015-07-10 */ -(function(){"use strict";angular.module("internationalPhoneNumber",[]).directive("internationalPhoneNumber",["$timeout",function(a){return{restrict:"A",require:"^ngModel",scope:{ngModel:"=",defaultCountry:"@"},link:function(b,c,d,e){var f,g,h,i;return e&&""!==c.val()&&a(function(){return c.intlTelInput("setNumber",c.val()),e.$setViewValue(c.val())},0),h=function(){return e.$setViewValue(c.val())},f=function(a){return a instanceof Array?a:a.toString().replace(/[ ]/g,"").split(",")},g={autoFormat:!0,autoHideDialCode:!0,defaultCountry:"",nationalMode:!1,numberType:"",onlyCountries:void 0,preferredCountries:["us","gb"],responsiveDropdown:!1,utilsScript:""},angular.forEach(g,function(a,b){var c;if(d.hasOwnProperty(b)&&angular.isDefined(d[b]))return c=d[b],"preferredCountries"===b?g.preferredCountries=f(c):"onlyCountries"===b?g.onlyCountries=f(c):"boolean"==typeof a?g[b]="true"===c:g[b]=c}),i=b.$watch("ngModel",function(a){return b.$$postDigest(function(){return g.defaultCountry=b.defaultCountry,null!==a&&void 0!==a&&""!==a&&c.val(a),c.intlTelInput(g),void 0!==d.skipUtilScriptDownload||g.utilsScript||c.intlTelInput("loadUtils","/bower_components/intl-tel-input/lib/libphonenumber/build/utils.js"),i()})}),e.$formatters.push(function(b){return b?(a(function(){return c.intlTelInput("setNumber",b)},0),c.val()):b}),e.$parsers.push(function(a){return a?a.replace(/[^\d]/g,""):a}),e.$validators.internationalPhoneNumber=function(a){return c.attr("required")?a?c.intlTelInput("isValidNumber"):!1:c.intlTelInput("getSelectedCountryData").dialCode===a?!0:a?c.intlTelInput("isValidNumber"):!0},c.on("blur keyup change",function(a){return b.$apply(h)}),c.on("$destroy",function(){return c.intlTelInput("destroy"),c.off("blur keyup change")})}}}])}).call(this); \ No newline at end of file +/*! international-phone-number 2015-08-26 */ +(function(){"use strict";angular.module("internationalPhoneNumber",[]).directive("internationalPhoneNumber",["$timeout",function(a){return{restrict:"A",require:"^ngModel",scope:{ngModel:"=",defaultCountry:"@"},link:function(b,c,d,e){var f,g,h,i;return e&&""!==c.val()&&a(function(){return c.intlTelInput("setNumber",c.val()),e.$setViewValue(c.val())},0),h=function(){return e.$setViewValue(c.val())},f=function(a){return a instanceof Array?a:a.toString().replace(/[ ]/g,"").split(",")},g={autoFormat:!0,autoHideDialCode:!0,defaultCountry:"",nationalMode:!1,numberType:"",onlyCountries:void 0,preferredCountries:["us","gb"],responsiveDropdown:!1,utilsScript:""},angular.forEach(g,function(a,b){var c;if(d.hasOwnProperty(b)&&angular.isDefined(d[b]))return c=d[b],"preferredCountries"===b?g.preferredCountries=f(c):"onlyCountries"===b?g.onlyCountries=f(c):"boolean"==typeof a?g[b]="true"===c:g[b]=c}),i=b.$watch("ngModel",function(a){return b.$$postDigest(function(){return g.defaultCountry=b.defaultCountry,null!==a&&void 0!==a&&""!==a&&c.val(a),c.intlTelInput(g),void 0!==d.skipUtilScriptDownload||g.utilsScript||c.intlTelInput("loadUtils","/bower_components/intl-tel-input/lib/libphonenumber/build/utils.js"),i()})}),e.$formatters.push(function(a){return a?(c.intlTelInput("setNumber",a),c.val()):a}),e.$parsers.push(function(a){return a?a.replace(/[^\d]/g,""):a}),e.$validators.internationalPhoneNumber=function(a){return a?c.intlTelInput("isValidNumber"):!0},c.on("blur keyup change",function(a){return b.$apply(h)}),c.on("$destroy",function(){return c.intlTelInput("destroy"),c.off("blur keyup change")})}}}])}).call(this); \ No newline at end of file diff --git a/src/international-phone-number.coffee b/src/international-phone-number.coffee index 1633f07..c023458 100644 --- a/src/international-phone-number.coffee +++ b/src/international-phone-number.coffee @@ -75,31 +75,21 @@ angular.module("internationalPhoneNumber", []).directive 'internationalPhoneNumb ctrl.$formatters.push (value) -> if !value return value - else - $timeout () -> - element.intlTelInput 'setNumber', value - , 0 - return element.val() + + element.intlTelInput 'setNumber', value + element.val() ctrl.$parsers.push (value) -> - return value if !value + if !value + return value + value.replace(/[^\d]/g, '') ctrl.$validators.internationalPhoneNumber = (value) -> - if element.attr('required') - if !value - return false - else - return element.intlTelInput("isValidNumber") - else - if element.intlTelInput("getSelectedCountryData").dialCode == value - return true - else - if !value - return true - else - return element.intlTelInput("isValidNumber") + if !value + return true + element.intlTelInput("isValidNumber") element.on 'blur keyup change', (event) -> scope.$apply read