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

Update to Address Widget #733

Open MB34 opened 9 years ago

MB34 commented 9 years ago

I have modified the Address Widget to have 3 lines, City, State, Postal Code/Zip, and Country.

/**
Address editable input.
Internally value stored as {city: "Moscow", address1: "Lenina", address2: "15"}

@class address
@extends abstractinput
@final
@example
<a href="#" id="address" data-type="address" data-pk="1">awesome</a>
<script>
$(function(){
    $('#address').editable({
        url: '/post',
        title: 'Enter city, address1 and address2 #',
        value: {
            city: "Moscow", 
            address1: "Lenina", 
            address2: "15"
        }
    });
});
</script>
**/
(function ($) {
    "use strict";

    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 Address = function (options) {
        this.init('address', options, Address.defaults);
    };

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

    $.extend(Address.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(value.address1).html() + '<br>' +
                       (value.address2.trim() != '' ? $('<div>').text(value.address2).html() + '<br>' : '') + 
                       (value.address3.trim() != '' ? $('<div>').text(value.address3).html() + '<br>' : '') + 
                       $('<div>').text(value.city).html() + ', ' +
                       $('<div>').text(value.state).html() + '<br>' +
                       $('<div>').text(value.zip).html() + '<br>' +
                       $('<div>').text(this.lookupcountry(value.ctry)).html();

            $(element).html(html); 
        },

        /**
        Gets value from element's html

        @method html2value(html) 
        **/        
        html2value: function(html) {  
            // 3630 N. Hills Dr., Austin, TX US
            // 3630 N. Hills Dr.<br />Austin, TX<br />US
            var v = html.split('<br>');
            switch (v.length) {
                case 4: // only one line
                    var cs = v[1].split(',');
                    return {address1: v[0].trim(),
                            address2: "",
                            address3: "",
                            city    : cs[0].trim(),
                            state   : cs[1].trim(),
                            zip     : v[2].trim(),
                            ctry    : v[3].trim()
                        };
                    break;
                case 5: // 2 lines
                    var cs = v[2].split(',');
                    return {address1: v[0].trim(),
                            address2: v[1].trim(),
                            address3: "",
                            city    : cs[0].trim(),
                            state   : cs[1].trim(),
                            zip     : v[3].trim(),
                            ctry    : v[4].trim()
                        };
                    break;
                case 6: // 3 lines
                    var cs = v[3].split(',');
                    return {address1: v[0].trim(),
                            address2: v[1].trim(),
                            address3: v[2].trim(),
                            city    : cs[0].trim(),
                            state   : cs[1].trim(),
                            zip     : v[4].trim(),
                            ctry    : v[5].trim()
                        };
                    break;
            }
        },

       /**
        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="address1"]').val(value.address1);
           this.$input.filter('[name="address2"]').val(value.address2);
           this.$input.filter('[name="address3"]').val(value.address3);
           this.$input.filter('[name="city"]').val(value.city);
           this.$input.filter('[name="state"]').val(value.state);
           this.$input.filter('[name="zip"]').val(value.zip);
           this.$input.filter('[name="ctry"]').val(value.ctry);
       },       

       /**
        Returns value of input.

        @method input2value() 
       **/          
       input2value: function() { 
           return {
              address1: this.$input.filter('[name="address1"]').val(), 
              address2: this.$input.filter('[name="address2"]').val(),
              address3: this.$input.filter('[name="address3"]').val(),
              city: this.$input.filter('[name="city"]').val(),
              state: this.$input.filter('[name="state"]').val(),
              zip: this.$input.filter('[name="zip"]').val(),
              ctry: this.$input.filter('[name="ctry"]').val()
           };
       },        

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

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

        @method activate() 
       **/        
       activate: function() {
            this.$input.filter('[name="address1"]').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();
                }
           });
       }       
    });

    Address.defaults = $.extend({}, $.fn.editabletypes.abstractinput.defaults, {
        tpl: '<div class="editable-address"><label><span>Line1:: </span><input type="text" id="address1" name="address1" class="input-large"></label></div>'+
             '<div class="editable-address"><label><span>Line2 (opt):: </span><input type="text" id="address2" name="address2" class="input-large"></label></div>'+
             '<div class="editable-address"><label><span>Line3 (opt):: </span><input type="text" id="address3" name="address3" class="input-large"></label></div>'+
             '<div class="editable-address"><label><span>City: </span><input type="text" id="city" name="city" class="input-large"></label></div>'+
             '<div class="editable-address"><label><span>State: </span><input type="text" id="state" name="state" class="input-small"></label></div>'+
             '<div class="editable-address"><label><span>Postal Code: </span><input type="text" id="zip" name="zip" class="input-small"></label></div>'+
             '<div class="editable-phone"><label><span>Country: </span><select id="ctry" name="ctry" style="width: 100%;">' + CountrySelect + '</select></label></div>',
        inputclass: ''
    });

    $.fn.editabletypes.address = Address;

}(window.jQuery));

This is the Countries data file used in this widget and the phone widget:

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"
   }
]
MB34 commented 9 years ago

You MUST include it before the address widget:

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

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