vitalets / x-editable

In-place editing with Twitter Bootstrap, jQuery UI or pure jQuery
http://vitalets.github.io/x-editable
MIT License
6.51k stars 1.72k forks source link

New Widget for Phone Numbers #729

Closed MB34 closed 9 years ago

MB34 commented 9 years ago

I’m trying to create a widget for phone numbers and want to add an option called hasext. This would allow a third field named Extension to be defined in the widget vs. just the original 2, Country Code and Number.

We have Business Phone numbers that have an extension and Cell Phone numbers that do not and I want to support both.

How do I add new options like this?

Below is my widget. Can anyone help out?

/**
Phone editable input.
Internally value stored as {"ctry: "1", num: "512-3496105", ext: ""}
ext is optional, to accept one, add hasext option when initializing, then value will be stored like this:
{"ctry: "1", num: "512-3496105"}

@class phone
@extends abstractinput
@final
@examples
<a href="#" id="phone" data-type="phone" data-pk="1">1-512-3496105</a>
<script>
$(function(){
    $('#phone').editable({
        url: '/post',
        title: 'Enter Phone Number',
        value: { // set from user data
            ctry: "1", 
            num: "512-3496105"
        }
    });
});
</script>

<a href="#" id="phone" data-type="phone" data-pk="1" data-hasext="1">1-512-3496105-1234</a>
<script>
$(function(){
    $('#phone').editable({
        url: '/post',
        title: 'Enter Phone Number',
        value: { // set from user data
            ctry: "1", 
            num: "512-3496105",
            ext: "1234"
        }
    });
});
</script>
**/
(function ($) {
    "use strict";

    /********************************************************************************************/
    // This code gets the list of countries from my MVC application and loads the Country Select
    /********************************************************************************************/
    var Countries = {};
    $.get("/Home/getCountries", function (data) {
        Countries = data;
    });
    var CountrySelect = "<select id=\"ctry\" name=\"ctry\" style=\"width: 100%;\">";
    for (x in Countries) {
       CountrySelect += "<option value=\""+x.CountryCode+"\">"+x.CountryName+"</option>";
    }
    CountrySelect += "</select>";
    /********************************************************************************************/

    var Phone = function (options) {
        this.init('phone', options, Phone.defaults);
    };

    //inherit from Abstract input
    $.fn.editableutils.inherit(Phone, $.fn.editabletypes.abstractinput);

    $.extend(Phone.prototype, {
        /**
        Renders input from tpl

        @method render() 
        **/        
        render: function() {
           this.$input = this.$tpl.find('input');
        },

        /**
        Default method to show value in element. Can be overwritten by display option.

        @method value2html(value, element) 
        **/
        value2html: function(value, element) {
            if(!value) {
                $(element).empty();
                return; 
            }
            var html = $('<div>').text(value.ctry).html() + '-' + 
                       $('<div>').text(value.num).html() + '-';
           if (this.options.hasext) {
                     html += $('<div>').text(value.ext).html();
                 }
            $(element).html(html); 
        },

        /**
        Gets value from element's html

        @method html2value(html) 
        **/        
        html2value: function(html) {        
          /*
            you may write parsing method to get value by element's html
            e.g. "1-512-3496105-1234" => {"ctry: "1", num: "512-3496105", ext: "1234"}
            but for complex structures it's not recommended.
            Better set value directly via javascript, e.g. 
            editable({
                value: {
                    ctry: "1", 
                    num: "512-3496105",
                    ext: "1234"
                }
            });
          */
          returnnull;  
        },

       /**
        Converts value to string. 
        It is used in internal comparing (not for sending to server).

        @method value2str(value)  
       **/
       value2str: function(value) {
           var str = '';
           if(value) {
               for(var k in value) {
                   str = str + k + ':' + value[k] + ';';  
               }
           }
           return str;
       }, 

       /*
        Converts string to value. Used for reading value from 'data-value' attribute.

        @method str2value(str)  
       */
       str2value: function(str) {
           /*
           this is mainly for parsing value defined in data-value attribute. 
           If you will always set value by javascript, no need to overwrite it
           */
           return str;
       },                

       /**
        Sets value of input.

        @method value2input(value) 
        @param {mixed} value
       **/         
       value2input: function(value) {
           if(!value) {
               return;
           }
           this.$input.filter('[name="ctry"]').val(value.ctry);
           this.$input.filter('[name="num"]').val(value.num);
           if (this.options.hasext) {
               this.$input.filter('[name="ext"]').val(value.ext);
           }
       },       

       /**
        Returns value of input.

        @method input2value() 
       **/          
       input2value: function() { 
           if (this.options.hasext) {
               return {
                   ctry: this.$input.filter('[name="ctry"]').val(),
                   num: this.$input.filter('[name="num"]').val(),
                   ext: this.$input.filter('[name="ext"]').val()
               };

           } else {
               return {
                   ctry: this.$input.filter('[name="ctry"]').val(),
                   num: this.$input.filter('[name="num"]').val()
               };

           }
       },        

        /**
        Activates input: sets focus on the first field.

        @method activate() 
       **/        
       activate: function() {
            this.$input.filter('[name="ctry"]').focus();
       },  

       /**
        Attaches handler to submit form in case of 'showbuttons=false' mode

        @method autosubmit() 
       **/       
       autosubmit: function() {
           this.$input.keydown(function (e) {
                if (e.which === 13) {
                    $(this).closest('form').submit();
                }
           });
       }       
    });

    if (this.options.hasext) {
        Phone.defaults = $.extend({}, $.fn.editabletypes.abstractinput.defaults, {
            tpl: '<div class="editable-phone"><label><span>Country: </span>' + CountrySelect + '</label></div>' + 
                  '<div class="editable-phone"><label><span>Number: </span><input type="text" name="num" class="input-small"></label></div>',
            inputclass: ''
        });
    } else {
        Phone.defaults = $.extend({}, $.fn.editabletypes.abstractinput.defaults, {      
            tpl: '<div class="editable-phone"><label><span>Country: </span>' + CountrySelect + '</label></div>'+
                 '<div class="editable-phone"><label><span>Number: </span><input type="text" name="num" class="input-small"></label></div>' +
                 '<div class="editable-phone"><label><span>Ext(opt.): </span><input type="text" name="ext" class="input-mini"></label></div>',
            inputclass: ''
        });
    }

    $.fn.editabletypes.phone = Phone;

}(window.jQuery));
MB34 commented 9 years ago

OK, I believe I have it working like I want now. I'm posting it here so people can learn from it. The only issue I've seen is that when setting the HTML value in the HTML, it sets the value for the control but doesn't format it the way it needs to like when you edit it.

/**
Phone editable input.
Internally value stored as {"ctry: "US", ac: "512", num: "3496105", ext: ""}

@class phone
@extends abstractinput
@final
@examples
<a href="#" id="phone" data-type="phone" data-pk="1">1-512-3496105-</a>
<script>
$(function(){
    $('#phone').editable({
        url: '/post',
        title: 'Enter Phone Number',
        value: {   // set from user data
            {
                ctry: "US", 
                ac: "512",
                num: "3496105"
                ext: ""
            }
        }
    });
});
</script>

<a href="#" id="phone" data-type="phone" data-pk="1" data-hasext="1">1-512-3496105-1234</a>
<script>
$(function(){
    $('#phone').editable({
        url: '/post',
        title: 'Enter Phone Number',
        value: { // set from user data
            {
                ctry: "1", 
                ac: "512",
                num: "512-3496105",
                ext: "1234"
            }
        }
    });
});
</script>
**/
(function ($) {
    "use strict";

    /********************************************************************************************/
    // This code gets the list of countries from my MVC application and loads the Country Select
    /********************************************************************************************/
    // var Countries = {};
    /*
    $.get("/Home/getCountries", function (data) {
        Countries = data;
    });
    */
    // var x = 0;
    var CountrySelect = "";

    for(var i=0;i<Countries.length;i++){
        var x = Countries[i];
        CountrySelect += "<option value=\""+x.country_code+"\">"+x.country_name+"</option>";
    }
    /********************************************************************************************/

    var Phone = function (options) {
        this.init('phone', options, Phone.defaults);
    };

    //inherit from Abstract input
    $.fn.editableutils.inherit(Phone, $.fn.editabletypes.abstractinput);

    $.extend(Phone.prototype, {
        /**
        Renders input from tpl

        @method render() 
        **/        
        render: function() {
           this.$input = this.$tpl.find('input,select');
        },

        /**
        Default method to show value in element. Can be overwritten by display option.

        @method value2html(value, element) 
        **/
        value2html: function(value, element) {
            if(!value) {
                $(element).empty();
                return; 
            }
            var html = $('<div>').text(this.lookupcountry(value.ctry)).html() + '-' + 
                       $('<div>').text(value.ac).html()  + '-' +
                       $('<div>').text(value.num).html()  + '-' +
                       $('<div>').text(value.ext).html();
            $(element).html(html); 
        },

        /**
        Gets value from element's html

        @method html2value(html) 
        **/        
        html2value: function(html) {        
            /*
                you may write parsing method to get value by element's html
                e.g. "1-512-3496105-1234" => {"ctry: "1", ac: "512", num: "3496105", ext: "1234"}
                but for complex structures it's not recommended.
                Better set value directly via javascript, e.g. 
                .editable({
                    value: {ctry: "1", 
                            ac: "512",
                            num: "3496105",
                            ext: "1234"
                            }
                });
            */
            var number = html.split('-');
            if(number.length > 0) {
                if(number.length == 5) {// has dash in number
                    var _num = number[2] + number[3];
                    var _ext = number[5];
                } else {
                    var _num = number[2];
                    var _ext = number[4];
                }
                return {"ctry": number[0], "ac": number[1], "num": _num, "ext": _ext};
            } else {
                return null;  
            }
        },

       /**
        Converts value to string. 
        It is used in internal comparing (not for sending to server).

        @method value2str(value)  
       **/
        value2str: function(value) {
            var str = '';
            if(value) {
                for(var k in value) {
                    str = str + k + ':' + value[k] + ';';  
                }
            }
            return str;
        }, 

        /*
         Converts string to value. Used for reading value from 'data-value' attribute.

         @method str2value(str)  
        */
        str2value: function(str) {
            /*
            this is mainly for parsing value defined in data-value attribute. 
            If you will always set value by javascript, no need to overwrite it
            */
            return str;
        },                

        /**
         Sets value of input.

         @method value2input(value) 
         @param {mixed} value
        **/         
        value2input: function(value) {
            if(!value) {
                return;
            }
            this.$input.filter('[name="ctry"]').val(value.ctry);
            this.$input.filter('[name="ac"]').val(value.ac);
            this.$input.filter('[name="num"]').val(value.num);
            this.$input.filter('[name="ext"]').val(value.ext);
        },       

        /**
         Returns value of input.

         @method input2value() 
        **/          
        input2value: function() { 
                return {
                    ctry: this.$input.filter('[name="ctry"]').val(),
                    ac:   this.$input.filter('[name="ac"]').val(),
                    num:  this.$input.filter('[name="num"]').val().replace('-', ''),
                    ext:  this.$input.filter('[name="ext"]').val()
            }
        },

        lookupcountry: function(value) {
            for(var i=0;i<Countries.length;i++){
                var x = Countries[i];
                if(x.country_code == value) {
                    return x.phone_cc;
                }
            }
            return 0;
        },

        /**
        Activates input: sets focus on the first field.

        @method activate() 
       **/        
       activate: function() {
            this.$input.filter('[name="ctry"]').focus();
       },  

        /**
         Attaches handler to submit form in case of 'showbuttons=false' mode

         @method autosubmit() 
        **/       
        autosubmit: function() {
            this.$input.keydown(function (e) {
                 if (e.which === 13) {
                     $(this).closest('form').submit();
                 }
            });
        }
    });
    Phone.defaults = $.extend({}, $.fn.editabletypes.abstractinput.defaults, {      
        tpl: '<div class="editable-phone"><label><span>Country: </span><select id="ctry" name="ctry" style="width: 100%;">' + CountrySelect + '</select></label></div>'+
             '<div class="editable-phone"><label><span>Area Code: </span><input type="text" name="ac" class="input-small"></label></div>' +
             '<div class="editable-phone"><label><span>Number: </span><input type="text" name="num" class="input-small"></label></div>' +
             '<div class="editable-phone"><label><span>Ext (opt): </span><input type="text" name="ext" class="input-mini"></label></div>',
        inputclass: ''
    });

    $.fn.editabletypes.phone = Phone;

}(window.jQuery));
MB34 commented 9 years ago

Here is the Countries data file. You MUST include it before the phone widget:

<!-- Countries Data -->
<script src="/files/bootstrap-editable/inputs-ext/phone/countries.json"></script>

<!-- phone input -->
<link href="/files/bootstrap-editable/inputs-ext/phone/phone.css" rel="stylesheet">
<script src="/files/bootstrap-editable/inputs-ext/phone/phone.js"></script>

var Countries = [  
   {  
      "country_code":"AF",
      "country_name":"Afghanistan",
      "phone_cc":"93"
   },
   {  
      "country_code":"AL",
      "country_name":"Albania",
      "phone_cc":"355"
   },
   {  
      "country_code":"DZ",
      "country_name":"Algeria",
      "phone_cc":"213"
   },
   {  
      "country_code":"AS",
      "country_name":"American Samoa",
      "phone_cc":"1684"
   },
   {  
      "country_code":"AD",
      "country_name":"Andorra",
      "phone_cc":"376"
   },
   {  
      "country_code":"AO",
      "country_name":"Angola",
      "phone_cc":"244"
   },
   {  
      "country_code":"AI",
      "country_name":"Anguilla",
      "phone_cc":"1264"
   },
   {  
      "country_code":"AQ",
      "country_name":"Antarctica",
      "phone_cc":"0"
   },
   {  
      "country_code":"AG",
      "country_name":"Antigua and Barbuda",
      "phone_cc":"1268"
   },
   {  
      "country_code":"AR",
      "country_name":"Argentina",
      "phone_cc":"54"
   },
   {  
      "country_code":"AM",
      "country_name":"Armenia",
      "phone_cc":"374"
   },
   {  
      "country_code":"AW",
      "country_name":"Aruba",
      "phone_cc":"297"
   },
   {  
      "country_code":"AU",
      "country_name":"Australia",
      "phone_cc":"61"
   },
   {  
      "country_code":"AT",
      "country_name":"Austria",
      "phone_cc":"43"
   },
   {  
      "country_code":"AZ",
      "country_name":"Azerbaijan",
      "phone_cc":"994"
   },
   {  
      "country_code":"BS",
      "country_name":"Bahamas",
      "phone_cc":"1242"
   },
   {  
      "country_code":"BH",
      "country_name":"Bahrain",
      "phone_cc":"973"
   },
   {  
      "country_code":"BD",
      "country_name":"Bangladesh",
      "phone_cc":"880"
   },
   {  
      "country_code":"BB",
      "country_name":"Barbados",
      "phone_cc":"1246"
   },
   {  
      "country_code":"BY",
      "country_name":"Belarus",
      "phone_cc":"375"
   },
   {  
      "country_code":"BE",
      "country_name":"Belgium",
      "phone_cc":"32"
   },
   {  
      "country_code":"BZ",
      "country_name":"Belize",
      "phone_cc":"501"
   },
   {  
      "country_code":"BJ",
      "country_name":"Benin",
      "phone_cc":"229"
   },
   {  
      "country_code":"BM",
      "country_name":"Bermuda",
      "phone_cc":"1441"
   },
   {  
      "country_code":"BT",
      "country_name":"Bhutan",
      "phone_cc":"975"
   },
   {  
      "country_code":"BO",
      "country_name":"Bolivia",
      "phone_cc":"591"
   },
   {  
      "country_code":"BA",
      "country_name":"Bosnia and Herzegovina",
      "phone_cc":"387"
   },
   {  
      "country_code":"BW",
      "country_name":"Botswana",
      "phone_cc":"267"
   },
   {  
      "country_code":"BV",
      "country_name":"Bouvet Island",
      "phone_cc":"0"
   },
   {  
      "country_code":"BR",
      "country_name":"Brazil",
      "phone_cc":"55"
   },
   {  
      "country_code":"IO",
      "country_name":"British Indian Ocean Territory",
      "phone_cc":"246"
   },
   {  
      "country_code":"BN",
      "country_name":"Brunei Darussalam",
      "phone_cc":"673"
   },
   {  
      "country_code":"BG",
      "country_name":"Bulgaria",
      "phone_cc":"359"
   },
   {  
      "country_code":"BF",
      "country_name":"Burkina Faso",
      "phone_cc":"226"
   },
   {  
      "country_code":"BI",
      "country_name":"Burundi",
      "phone_cc":"257"
   },
   {  
      "country_code":"KH",
      "country_name":"Cambodia",
      "phone_cc":"855"
   },
   {  
      "country_code":"CM",
      "country_name":"Cameroon",
      "phone_cc":"237"
   },
   {  
      "country_code":"CA",
      "country_name":"Canada",
      "phone_cc":"1"
   },
   {  
      "country_code":"CV",
      "country_name":"Cape Verde",
      "phone_cc":"238"
   },
   {  
      "country_code":"KY",
      "country_name":"Cayman Islands",
      "phone_cc":"1345"
   },
   {  
      "country_code":"CF",
      "country_name":"Central African Republic",
      "phone_cc":"236"
   },
   {  
      "country_code":"TD",
      "country_name":"Chad",
      "phone_cc":"235"
   },
   {  
      "country_code":"CL",
      "country_name":"Chile",
      "phone_cc":"56"
   },
   {  
      "country_code":"CN",
      "country_name":"China",
      "phone_cc":"86"
   },
   {  
      "country_code":"CX",
      "country_name":"Christmas Island",
      "phone_cc":"61"
   },
   {  
      "country_code":"CC",
      "country_name":"Cocos (Keeling) Islands",
      "phone_cc":"672"
   },
   {  
      "country_code":"CO",
      "country_name":"Colombia",
      "phone_cc":"57"
   },
   {  
      "country_code":"KM",
      "country_name":"Comoros",
      "phone_cc":"269"
   },
   {  
      "country_code":"CG",
      "country_name":"Congo",
      "phone_cc":"242"
   },
   {  
      "country_code":"CD",
      "country_name":"Congo, the Democratic Republic of the",
      "phone_cc":"242"
   },
   {  
      "country_code":"CK",
      "country_name":"Cook Islands",
      "phone_cc":"682"
   },
   {  
      "country_code":"CR",
      "country_name":"Costa Rica",
      "phone_cc":"506"
   },
   {  
      "country_code":"CI",
      "country_name":"Cote D'Ivoire",
      "phone_cc":"225"
   },
   {  
      "country_code":"HR",
      "country_name":"Croatia",
      "phone_cc":"385"
   },
   {  
      "country_code":"CU",
      "country_name":"Cuba",
      "phone_cc":"53"
   },
   {  
      "country_code":"CY",
      "country_name":"Cyprus",
      "phone_cc":"357"
   },
   {  
      "country_code":"CZ",
      "country_name":"Czech Republic",
      "phone_cc":"420"
   },
   {  
      "country_code":"DK",
      "country_name":"Denmark",
      "phone_cc":"45"
   },
   {  
      "country_code":"DJ",
      "country_name":"Djibouti",
      "phone_cc":"253"
   },
   {  
      "country_code":"DM",
      "country_name":"Dominica",
      "phone_cc":"1767"
   },
   {  
      "country_code":"DO",
      "country_name":"Dominican Republic",
      "phone_cc":"1809"
   },
   {  
      "country_code":"EC",
      "country_name":"Ecuador",
      "phone_cc":"593"
   },
   {  
      "country_code":"EG",
      "country_name":"Egypt",
      "phone_cc":"20"
   },
   {  
      "country_code":"SV",
      "country_name":"El Salvador",
      "phone_cc":"503"
   },
   {  
      "country_code":"GQ",
      "country_name":"Equatorial Guinea",
      "phone_cc":"240"
   },
   {  
      "country_code":"ER",
      "country_name":"Eritrea",
      "phone_cc":"291"
   },
   {  
      "country_code":"EE",
      "country_name":"Estonia",
      "phone_cc":"372"
   },
   {  
      "country_code":"ET",
      "country_name":"Ethiopia",
      "phone_cc":"251"
   },
   {  
      "country_code":"FK",
      "country_name":"Falkland Islands (Malvinas)",
      "phone_cc":"500"
   },
   {  
      "country_code":"FO",
      "country_name":"Faroe Islands",
      "phone_cc":"298"
   },
   {  
      "country_code":"FJ",
      "country_name":"Fiji",
      "phone_cc":"679"
   },
   {  
      "country_code":"FI",
      "country_name":"Finland",
      "phone_cc":"358"
   },
   {  
      "country_code":"FR",
      "country_name":"France",
      "phone_cc":"33"
   },
   {  
      "country_code":"GF",
      "country_name":"French Guiana",
      "phone_cc":"594"
   },
   {  
      "country_code":"PF",
      "country_name":"French Polynesia",
      "phone_cc":"689"
   },
   {  
      "country_code":"TF",
      "country_name":"French Southern Territories",
      "phone_cc":"0"
   },
   {  
      "country_code":"GA",
      "country_name":"Gabon",
      "phone_cc":"241"
   },
   {  
      "country_code":"GM",
      "country_name":"Gambia",
      "phone_cc":"220"
   },
   {  
      "country_code":"GE",
      "country_name":"Georgia",
      "phone_cc":"995"
   },
   {  
      "country_code":"DE",
      "country_name":"Germany",
      "phone_cc":"49"
   },
   {  
      "country_code":"GH",
      "country_name":"Ghana",
      "phone_cc":"233"
   },
   {  
      "country_code":"GI",
      "country_name":"Gibraltar",
      "phone_cc":"350"
   },
   {  
      "country_code":"GR",
      "country_name":"Greece",
      "phone_cc":"30"
   },
   {  
      "country_code":"GL",
      "country_name":"Greenland",
      "phone_cc":"299"
   },
   {  
      "country_code":"GD",
      "country_name":"Grenada",
      "phone_cc":"1473"
   },
   {  
      "country_code":"GP",
      "country_name":"Guadeloupe",
      "phone_cc":"590"
   },
   {  
      "country_code":"GU",
      "country_name":"Guam",
      "phone_cc":"1671"
   },
   {  
      "country_code":"GT",
      "country_name":"Guatemala",
      "phone_cc":"502"
   },
   {  
      "country_code":"GN",
      "country_name":"Guinea",
      "phone_cc":"224"
   },
   {  
      "country_code":"GW",
      "country_name":"Guinea-Bissau",
      "phone_cc":"245"
   },
   {  
      "country_code":"GY",
      "country_name":"Guyana",
      "phone_cc":"592"
   },
   {  
      "country_code":"HT",
      "country_name":"Haiti",
      "phone_cc":"509"
   },
   {  
      "country_code":"HM",
      "country_name":"Heard Island and Mcdonald Islands",
      "phone_cc":"0"
   },
   {  
      "country_code":"VA",
      "country_name":"Holy See (Vatican City State)",
      "phone_cc":"39"
   },
   {  
      "country_code":"HN",
      "country_name":"Honduras",
      "phone_cc":"504"
   },
   {  
      "country_code":"HK",
      "country_name":"Hong Kong",
      "phone_cc":"852"
   },
   {  
      "country_code":"HU",
      "country_name":"Hungary",
      "phone_cc":"36"
   },
   {  
      "country_code":"IS",
      "country_name":"Iceland",
      "phone_cc":"354"
   },
   {  
      "country_code":"IN",
      "country_name":"India",
      "phone_cc":"91"
   },
   {  
      "country_code":"ID",
      "country_name":"Indonesia",
      "phone_cc":"62"
   },
   {  
      "country_code":"IR",
      "country_name":"Iran, Islamic Republic of",
      "phone_cc":"98"
   },
   {  
      "country_code":"IQ",
      "country_name":"Iraq",
      "phone_cc":"964"
   },
   {  
      "country_code":"IE",
      "country_name":"Ireland",
      "phone_cc":"353"
   },
   {  
      "country_code":"IL",
      "country_name":"Israel",
      "phone_cc":"972"
   },
   {  
      "country_code":"IT",
      "country_name":"Italy",
      "phone_cc":"39"
   },
   {  
      "country_code":"JM",
      "country_name":"Jamaica",
      "phone_cc":"1876"
   },
   {  
      "country_code":"JP",
      "country_name":"Japan",
      "phone_cc":"81"
   },
   {  
      "country_code":"JO",
      "country_name":"Jordan",
      "phone_cc":"962"
   },
   {  
      "country_code":"KZ",
      "country_name":"Kazakhstan",
      "phone_cc":"7"
   },
   {  
      "country_code":"KE",
      "country_name":"Kenya",
      "phone_cc":"254"
   },
   {  
      "country_code":"KI",
      "country_name":"Kiribati",
      "phone_cc":"686"
   },
   {  
      "country_code":"KP",
      "country_name":"Korea, Democratic People's Republic of",
      "phone_cc":"850"
   },
   {  
      "country_code":"KR",
      "country_name":"Korea, Republic of",
      "phone_cc":"82"
   },
   {  
      "country_code":"KW",
      "country_name":"Kuwait",
      "phone_cc":"965"
   },
   {  
      "country_code":"KG",
      "country_name":"Kyrgyzstan",
      "phone_cc":"996"
   },
   {  
      "country_code":"LA",
      "country_name":"Lao People's Democratic Republic",
      "phone_cc":"856"
   },
   {  
      "country_code":"LV",
      "country_name":"Latvia",
      "phone_cc":"371"
   },
   {  
      "country_code":"LB",
      "country_name":"Lebanon",
      "phone_cc":"961"
   },
   {  
      "country_code":"LS",
      "country_name":"Lesotho",
      "phone_cc":"266"
   },
   {  
      "country_code":"LR",
      "country_name":"Liberia",
      "phone_cc":"231"
   },
   {  
      "country_code":"LY",
      "country_name":"Libyan Arab Jamahiriya",
      "phone_cc":"218"
   },
   {  
      "country_code":"LI",
      "country_name":"Liechtenstein",
      "phone_cc":"423"
   },
   {  
      "country_code":"LT",
      "country_name":"Lithuania",
      "phone_cc":"370"
   },
   {  
      "country_code":"LU",
      "country_name":"Luxembourg",
      "phone_cc":"352"
   },
   {  
      "country_code":"MO",
      "country_name":"Macao",
      "phone_cc":"853"
   },
   {  
      "country_code":"MK",
      "country_name":"Macedonia, the Former Yugoslav Republic of",
      "phone_cc":"389"
   },
   {  
      "country_code":"MG",
      "country_name":"Madagascar",
      "phone_cc":"261"
   },
   {  
      "country_code":"MW",
      "country_name":"Malawi",
      "phone_cc":"265"
   },
   {  
      "country_code":"MY",
      "country_name":"Malaysia",
      "phone_cc":"60"
   },
   {  
      "country_code":"MV",
      "country_name":"Maldives",
      "phone_cc":"960"
   },
   {  
      "country_code":"ML",
      "country_name":"Mali",
      "phone_cc":"223"
   },
   {  
      "country_code":"MT",
      "country_name":"Malta",
      "phone_cc":"356"
   },
   {  
      "country_code":"MH",
      "country_name":"Marshall Islands",
      "phone_cc":"692"
   },
   {  
      "country_code":"MQ",
      "country_name":"Martinique",
      "phone_cc":"596"
   },
   {  
      "country_code":"MR",
      "country_name":"Mauritania",
      "phone_cc":"222"
   },
   {  
      "country_code":"MU",
      "country_name":"Mauritius",
      "phone_cc":"230"
   },
   {  
      "country_code":"YT",
      "country_name":"Mayotte",
      "phone_cc":"269"
   },
   {  
      "country_code":"MX",
      "country_name":"Mexico",
      "phone_cc":"52"
   },
   {  
      "country_code":"FM",
      "country_name":"Micronesia, Federated States of",
      "phone_cc":"691"
   },
   {  
      "country_code":"MD",
      "country_name":"Moldova, Republic of",
      "phone_cc":"373"
   },
   {  
      "country_code":"MC",
      "country_name":"Monaco",
      "phone_cc":"377"
   },
   {  
      "country_code":"MN",
      "country_name":"Mongolia",
      "phone_cc":"976"
   },
   {  
      "country_code":"MS",
      "country_name":"Montserrat",
      "phone_cc":"1664"
   },
   {  
      "country_code":"MA",
      "country_name":"Morocco",
      "phone_cc":"212"
   },
   {  
      "country_code":"MZ",
      "country_name":"Mozambique",
      "phone_cc":"258"
   },
   {  
      "country_code":"MM",
      "country_name":"Myanmar",
      "phone_cc":"95"
   },
   {  
      "country_code":"NA",
      "country_name":"Namibia",
      "phone_cc":"264"
   },
   {  
      "country_code":"NR",
      "country_name":"Nauru",
      "phone_cc":"674"
   },
   {  
      "country_code":"NP",
      "country_name":"Nepal",
      "phone_cc":"977"
   },
   {  
      "country_code":"NL",
      "country_name":"Netherlands",
      "phone_cc":"31"
   },
   {  
      "country_code":"AN",
      "country_name":"Netherlands Antilles",
      "phone_cc":"599"
   },
   {  
      "country_code":"NC",
      "country_name":"New Caledonia",
      "phone_cc":"687"
   },
   {  
      "country_code":"NZ",
      "country_name":"New Zealand",
      "phone_cc":"64"
   },
   {  
      "country_code":"NI",
      "country_name":"Nicaragua",
      "phone_cc":"505"
   },
   {  
      "country_code":"NE",
      "country_name":"Niger",
      "phone_cc":"227"
   },
   {  
      "country_code":"NG",
      "country_name":"Nigeria",
      "phone_cc":"234"
   },
   {  
      "country_code":"NU",
      "country_name":"Niue",
      "phone_cc":"683"
   },
   {  
      "country_code":"NF",
      "country_name":"Norfolk Island",
      "phone_cc":"672"
   },
   {  
      "country_code":"MP",
      "country_name":"Northern Mariana Islands",
      "phone_cc":"1670"
   },
   {  
      "country_code":"NO",
      "country_name":"Norway",
      "phone_cc":"47"
   },
   {  
      "country_code":"OM",
      "country_name":"Oman",
      "phone_cc":"968"
   },
   {  
      "country_code":"PK",
      "country_name":"Pakistan",
      "phone_cc":"92"
   },
   {  
      "country_code":"PW",
      "country_name":"Palau",
      "phone_cc":"680"
   },
   {  
      "country_code":"PS",
      "country_name":"Palestinian Territory, Occupied",
      "phone_cc":"970"
   },
   {  
      "country_code":"PA",
      "country_name":"Panama",
      "phone_cc":"507"
   },
   {  
      "country_code":"PG",
      "country_name":"Papua New Guinea",
      "phone_cc":"675"
   },
   {  
      "country_code":"PY",
      "country_name":"Paraguay",
      "phone_cc":"595"
   },
   {  
      "country_code":"PE",
      "country_name":"Peru",
      "phone_cc":"51"
   },
   {  
      "country_code":"PH",
      "country_name":"Philippines",
      "phone_cc":"63"
   },
   {  
      "country_code":"PN",
      "country_name":"Pitcairn",
      "phone_cc":"0"
   },
   {  
      "country_code":"PL",
      "country_name":"Poland",
      "phone_cc":"48"
   },
   {  
      "country_code":"PT",
      "country_name":"Portugal",
      "phone_cc":"351"
   },
   {  
      "country_code":"PR",
      "country_name":"Puerto Rico",
      "phone_cc":"1787"
   },
   {  
      "country_code":"QA",
      "country_name":"Qatar",
      "phone_cc":"974"
   },
   {  
      "country_code":"RE",
      "country_name":"Reunion",
      "phone_cc":"262"
   },
   {  
      "country_code":"RO",
      "country_name":"Romania",
      "phone_cc":"40"
   },
   {  
      "country_code":"RU",
      "country_name":"Russian Federation",
      "phone_cc":"70"
   },
   {  
      "country_code":"RW",
      "country_name":"Rwanda",
      "phone_cc":"250"
   },
   {  
      "country_code":"SH",
      "country_name":"Saint Helena",
      "phone_cc":"290"
   },
   {  
      "country_code":"KN",
      "country_name":"Saint Kitts and Nevis",
      "phone_cc":"1869"
   },
   {  
      "country_code":"LC",
      "country_name":"Saint Lucia",
      "phone_cc":"1758"
   },
   {  
      "country_code":"PM",
      "country_name":"Saint Pierre and Miquelon",
      "phone_cc":"508"
   },
   {  
      "country_code":"VC",
      "country_name":"Saint Vincent and the Grenadines",
      "phone_cc":"1784"
   },
   {  
      "country_code":"WS",
      "country_name":"Samoa",
      "phone_cc":"684"
   },
   {  
      "country_code":"SM",
      "country_name":"San Marino",
      "phone_cc":"378"
   },
   {  
      "country_code":"ST",
      "country_name":"Sao Tome and Principe",
      "phone_cc":"239"
   },
   {  
      "country_code":"SA",
      "country_name":"Saudi Arabia",
      "phone_cc":"966"
   },
   {  
      "country_code":"SN",
      "country_name":"Senegal",
      "phone_cc":"221"
   },
   {  
      "country_code":"CS",
      "country_name":"Serbia and Montenegro",
      "phone_cc":"381"
   },
   {  
      "country_code":"SC",
      "country_name":"Seychelles",
      "phone_cc":"248"
   },
   {  
      "country_code":"SL",
      "country_name":"Sierra Leone",
      "phone_cc":"232"
   },
   {  
      "country_code":"SG",
      "country_name":"Singapore",
      "phone_cc":"65"
   },
   {  
      "country_code":"SK",
      "country_name":"Slovakia",
      "phone_cc":"421"
   },
   {  
      "country_code":"SI",
      "country_name":"Slovenia",
      "phone_cc":"386"
   },
   {  
      "country_code":"SB",
      "country_name":"Solomon Islands",
      "phone_cc":"677"
   },
   {  
      "country_code":"SO",
      "country_name":"Somalia",
      "phone_cc":"252"
   },
   {  
      "country_code":"ZA",
      "country_name":"South Africa",
      "phone_cc":"27"
   },
   {  
      "country_code":"GS",
      "country_name":"South Georgia and the South Sandwich Islands",
      "phone_cc":"0"
   },
   {  
      "country_code":"ES",
      "country_name":"Spain",
      "phone_cc":"34"
   },
   {  
      "country_code":"LK",
      "country_name":"Sri Lanka",
      "phone_cc":"94"
   },
   {  
      "country_code":"SD",
      "country_name":"Sudan",
      "phone_cc":"249"
   },
   {  
      "country_code":"SR",
      "country_name":"Suriname",
      "phone_cc":"597"
   },
   {  
      "country_code":"SJ",
      "country_name":"Svalbard and Jan Mayen",
      "phone_cc":"47"
   },
   {  
      "country_code":"SZ",
      "country_name":"Swaziland",
      "phone_cc":"268"
   },
   {  
      "country_code":"SE",
      "country_name":"Sweden",
      "phone_cc":"46"
   },
   {  
      "country_code":"CH",
      "country_name":"Switzerland",
      "phone_cc":"41"
   },
   {  
      "country_code":"SY",
      "country_name":"Syrian Arab Republic",
      "phone_cc":"963"
   },
   {  
      "country_code":"TW",
      "country_name":"Taiwan, Province of China",
      "phone_cc":"886"
   },
   {  
      "country_code":"TJ",
      "country_name":"Tajikistan",
      "phone_cc":"992"
   },
   {  
      "country_code":"TZ",
      "country_name":"Tanzania, United Republic of",
      "phone_cc":"255"
   },
   {  
      "country_code":"TH",
      "country_name":"Thailand",
      "phone_cc":"66"
   },
   {  
      "country_code":"TL",
      "country_name":"Timor-Leste",
      "phone_cc":"670"
   },
   {  
      "country_code":"TG",
      "country_name":"Togo",
      "phone_cc":"228"
   },
   {  
      "country_code":"TK",
      "country_name":"Tokelau",
      "phone_cc":"690"
   },
   {  
      "country_code":"TO",
      "country_name":"Tonga",
      "phone_cc":"676"
   },
   {  
      "country_code":"TT",
      "country_name":"Trinidad and Tobago",
      "phone_cc":"1868"
   },
   {  
      "country_code":"TN",
      "country_name":"Tunisia",
      "phone_cc":"216"
   },
   {  
      "country_code":"TR",
      "country_name":"Turkey",
      "phone_cc":"90"
   },
   {  
      "country_code":"TM",
      "country_name":"Turkmenistan",
      "phone_cc":"7370"
   },
   {  
      "country_code":"TC",
      "country_name":"Turks and Caicos Islands",
      "phone_cc":"1649"
   },
   {  
      "country_code":"TV",
      "country_name":"Tuvalu",
      "phone_cc":"688"
   },
   {  
      "country_code":"UG",
      "country_name":"Uganda",
      "phone_cc":"256"
   },
   {  
      "country_code":"UA",
      "country_name":"Ukraine",
      "phone_cc":"380"
   },
   {  
      "country_code":"AE",
      "country_name":"United Arab Emirates",
      "phone_cc":"971"
   },
   {  
      "country_code":"GB",
      "country_name":"United Kingdom",
      "phone_cc":"44"
   },
   {  
      "country_code":"US",
      "country_name":"United States",
      "phone_cc":"1"
   },
   {  
      "country_code":"UM",
      "country_name":"United States Minor Outlying Islands",
      "phone_cc":"1"
   },
   {  
      "country_code":"UY",
      "country_name":"Uruguay",
      "phone_cc":"598"
   },
   {  
      "country_code":"UZ",
      "country_name":"Uzbekistan",
      "phone_cc":"998"
   },
   {  
      "country_code":"VU",
      "country_name":"Vanuatu",
      "phone_cc":"678"
   },
   {  
      "country_code":"VE",
      "country_name":"Venezuela",
      "phone_cc":"58"
   },
   {  
      "country_code":"VN",
      "country_name":"Viet Nam",
      "phone_cc":"84"
   },
   {  
      "country_code":"VG",
      "country_name":"Virgin Islands, British",
      "phone_cc":"1284"
   },
   {  
      "country_code":"VI",
      "country_name":"Virgin Islands, U.s.",
      "phone_cc":"1340"
   },
   {  
      "country_code":"WF",
      "country_name":"Wallis and Futuna",
      "phone_cc":"681"
   },
   {  
      "country_code":"EH",
      "country_name":"Western Sahara",
      "phone_cc":"212"
   },
   {  
      "country_code":"YE",
      "country_name":"Yemen",
      "phone_cc":"967"
   },
   {  
      "country_code":"ZM",
      "country_name":"Zambia",
      "phone_cc":"260"
   },
   {  
      "country_code":"ZW",
      "country_name":"Zimbabwe",
      "phone_cc":"263"
   }
]