Coder Social home page Coder Social logo

country-state-select's Introduction

Country State Select

Build Status
Code Climate

Country State Select is a library that provides an easy API to generate Country , State / Province and City dropdowns for use in forms.

When implemented correctly, a State / Province dropdown is filled with appropriate regions based upon what Country a user has selected .

For instance, if a user chooses "United States of America" for a Country dropdown, the State dropdown will be filled with the 50 appropriate states plus the District of Columbia also then user can list city according to state selection but currently cities are limited.

The data for Countries and States is populated by the excellent city-state gem.

Demo

https://country-state-select.herokuapp.com

Getting Started

Country State Select is released as a Ruby Gem and requires the Rails environment as well.

To install, simply add the following to your Gemfile.

gem 'country_state_select'

Then run

bundle install

NOTE

In the latest version we have removed all the dependencies of js and you are feel free to use any js you can use predefine method to populate data

Don't forget to restart your server after you install it.

Setup Gem

if not autoloaded than please add in your application.js //= require country_state_select

chosen JavaScript assets

The application makes use of the chosen-rails library for a better user experience. This can be disabled if desired.

If you're using chosen-rails, please add the following to app/assets/javascripts/application.js:

  //= require chosen-jquery

chosen CSS assets

You'll also need to add the chosen-rails stylesheet.

If you're using chosen-rails, please add the following to app/assets/stylesheets/application.css:

*= require chosen

or

@import "chosen";

Form Implementation in SimpleForm

Implementation in a view is simple.

Just create a simple_form object like so:

<%= simple_form_for @form_object do |f| 
  f.button :submit
end %>

Once your form object is created, add in fields for your user to select a Country and State / Province.

Country Field

To add the Country field, add an input field like the following:

<%= f.input :country_field, collection: CountryStateSelect.countries_collection %>

The above code is simply a normal simple_form field object with a collection of countries passed to it using the CountryStateSelect library.

You can pass any of the normal options that a field object accepts - :label, :input_html, etc.

States / Provinces Field

To list the States / Provinces, add an input field like the following:

<%= options = { form: f, field_names: { :country => :country_field, :state => :state_field } }

f.input :state_field, CountryStateSelect.state_options(options) %>

It's important to note that the :country and :state keys in the :field_names object must contain the correct values in order for the correct States / Provinces to load into the window.

Other than that, it's yet another standard simple_form field object.

Any options that are valid in simple_form field can be passed into the options hash.

Required JavaScript

The magic of the library is the JavaScript that is performed on the fields. This JavaScript needs to be included in order for the proper State / Provinces to be selected based upon your Country selection.

Add this JavaScript to the page that is loading your form:

$(document).on('ready page:load', function() {
  return CountryStateSelect({
    country_id: "country_field_id",
    state_id: "state_field_id"
  });
});

If you are using CoffeeScript, use the following:

$(document).on 'ready page:load', ->
    CountryStateSelect({ country_id: "country_field_id", state_id: "state_field_id" })

The country_id accepts the form ID for the country field. The state_id accepts the form ID for the state field.

The easiest way to determine the ID is to view the source in the web browser. (Or, you could set it in the options hash.)

The ID being referred to is like the following in a select menu:

<select id="country_field_id"></select>

chosen UI improvements (optional)

The CountryStateSelect interface offers the option to turn the Chosen library on or off.

To turn it on, set it to true:

$(document).on('ready page:load', function() {
  return CountryStateSelect({
    chosen_ui: true,
    chosen_options: { 
      disable_search_threshold: 10,
      width: '95%'
    },
    ...
    ...
    ...
  });
}); 

To turn it off, set it to false:

$(document).on('ready page:load', function() {
  return CountryStateSelect({
    chosen_ui: false,
    ...
    ...
    ...
  });
});

Contributing

Fork, fix, then send a pull request.

country-state-select's People

Contributors

aldefouw avatar alse avatar arvind-vyas avatar arvindvyas avatar denisahearn avatar hitendrachauhan avatar randalmills2 avatar redtachyons avatar sachin87 avatar said210 avatar sighmon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

country-state-select's Issues

JavaScript manifest

Hi @arvindvyas -

I think the README might skip the step where the JavaScript assets are loaded into the manifest:

//= require country_state_select

Or perhaps I am blind. If it isn't in there, we should probably add it perhaps?

can we use select2 also in this

Currently we are using chosen select , How we can configure this so that other can use what ever they want to use for select , for now only select2

Doesn't work with rails 4.2.6

Added to Gemfile:
gem 'country_state_select', '>= 3.0.2'

bundle install throws an error due to dependency issues on older version of compass-rails. Is there any reason for sticking to 2.0.4?

Fetching gem metadata from https://rubygems.org/
Fetching version metadata from https://rubygems.org/
Fetching dependency metadata from https://rubygems.org/
Resolving dependencies....
Bundler could not find compatible versions for gem "sprockets":
In snapshot (Gemfile.lock):
sprockets (= 3.6.0)

In Gemfile:
country_state_select (>= 3.0.2) was resolved to 3.0.2, which depends on
compass-rails (~> 2.0.4) was resolved to 2.0.4, which depends on
sprockets (< 2.13)

haml_coffee_assets was resolved to 1.17.0, which depends on
  sprockets (>= 2.0)

sass-rails (~> 5.0) was resolved to 5.0.4, which depends on
  sprockets (< 4.0, >= 2.8)

sprockets-es6 was resolved to 0.9.0, which depends on
  sprockets (>= 3.0.0)

sprockets-es6 was resolved to 0.9.0, which depends on
  sprockets (>= 3.0.0)

sprockets-es6 was resolved to 0.9.0, which depends on
  sprockets (>= 3.0.0)

Running bundle update will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

Version Note

Hi Arvind -

Great work on adding the Cities to the gem. Looks great. I might do a few pull requests in the future to clean up a few things that I noticed, but it looks really great overall.

I was wondering if we need to create a git tag for version 3.0. I see that versioning stops at 2.0.0 in git. Rubygems appears to use the git tags to show releases.

If we want to follow Semantic versioning, which I think is a good idea, we should follow this guide:
http://semver.org/

That would put the gem at version 3.0.x because we have completely changed the public interface. We should also change the version file in the gem itselt each time we cut a new release.

I think we should probably update the version to be like 3.0.x and do a git tag to reflect it.

Thoughts?

Thanks,
Adam D.

on changing country states don't load

I added in registration.js (according to my layout)

//= require chosen-jquery
//= require country_state_select

in registration.css
@import "chosen";

in form

= f.input :country_field, collection: CountryStateSelect.countries_collection
- options = { form: f, field_names: { :country => :country_field, :state => :state_field } }
= f.input :state_field, CountryStateSelect.state_options(options)

in js at end of from

= content_for :javascript
  javascript:
    $(document).on('ready page:load', function() {
      return CountryStateSelect({
        country_id: "country_field_id",
        state_id: "state_field_id"
      });
    });

States load first time but on changing country states remain same (which loaded first time)
Did I miss something?

Add Rails 5 support

The gem seems to work fine with Rails 5. You just need to add this line to the 'country_state_select.rb' file in the /lib/ directory:

when /^5/
    require 'country_state_select/engine'

Should be a pretty easy add.

I also had to change this runtime dependency:

spec.add_runtime_dependency 'compass-rails', '>= 2.0.4'

NoMethodError for countries_collection

CountryStateSelect.countries_collection
NoMethodError: undefined method `countries_collection' for CountryStateSelect:Module

The gem is installed correctly
CountryStateSelect.countries_except("foo")
=> [[:AD, "Andorra"],
 [:AE, "United Arab Emirates"],
 [:AF, "Afghanistan"],
 [:AG, "Antigua and Barbuda"],

version 2.0.0

Compatability without simple_form

I want to use this gem without having to use simple_form.
I already have an established app with many forms that i need to add this country/state functionality to.

Problems with City selection

  • When you select a new country or state, the city field should really be reset. It doesn't appear to do that right now.
  • Also need to create a #city_options public method where it can gather a collection based upon the state selection, similar to what the #state_options method does right now.

Still need to fix the tests and dummy application as well.

chosenIsRequired function

For people who are NOT using chosen:

I could not get this to work unless i modified these sections

  function addChosenToState(){
    if (chosenIsRequired && stateIsNotText()) {
      $('#' + state_id).chosen();
    }
  }

to this

  function addChosenToState(){
    if (chosenIsRequired() && stateIsNotText()) {
      $('#' + state_id).chosen();
    }
  }

(the chosenIsRequired as a function call)
in https://github.com/arvindvyas/Country-State-Select/blob/master/vendor/assets/javascript/country_state_select.js.erb

Seems that is nor working with Rails 5.

I added the gem to my Gemfile as recommended.

gem 'country_state_select'

I executed the bundle install / update commands and when attempting to restart the server I got this error as shown below.

rails s
/Users/liviu-mac/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:89:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'country_state_select'. (Bundler::GemRequireError)
Gem Load Error is: Unsupported rails version

Be careful with catch-all routing in your application

On one of the applications that I used this gem in, I had a route matcher at the end of the routes.rb file.

Something like this:

match '*unmatched_route', to: 'application#not_found', :via => :all

All was fine and dandy, but suddenly the POST routes for this gem (which are crucial to the gem) stopped working.

You know why?

Because of the order that the routes were configured in the manifest, #find_states and #find_cities was no longer routing to the CscsController.

They were now routing to the ApplicationController#not_found.

@arvindvyas - See my post below for how I fixed this ....

Not able to select state according to selected country

Hi I am using gem and I had done

<%= f.select :country, CountryStateSelect::Constant::COUNTRIES, {}, id: 'country_id' %>
so it shows me all the country list. Now I want when I select country then in other drop-down it will show list of all states.
When i write this then also nothing happens. It does not populate states.
<%= f.text_field :state_name ,:id=> 'state_name'%>

'Undefined' is first option in State Dropdown

Hi Arvind -

I think that there may be an issue with the latest version 3.0.2.

When I select the Country, the States are populated, but the first value is "undefined."

Are you able to reproduce that behavior on your end?

I did notice that you did some refactoring to the code a while back. If this is an issue and not just some stupid setup issue on my part, perhaps you might look at that refactored code?

Thanks,
Adam

undefined method 'countries_collection' for CountryStateSelect:Module

I'm not sure what I'm missing here, but I've added the gem to my Rails 4.2.4 Gemfile, done a bundle install, and a restart of my web server.

In trying this:
<%= form_for package do |f| %>
<%= f.select :delivery_country, collection: CountryStateSelect.countries_collection %>

I seem only to get
undefined method 'countries_collection' for CountryStateSelect:Module

Any ideas?

Need to look how we can add more cities

Need to look city-state gem , for update cities , in our gem , currently I have seen there are lots of cities are not available , need to check how we can update that data

Change gem name

Is it will be good idea to change gem name 'country_state_select' to country-state-select

Because if we write like this then we can easily find it when we do google ?

country-state-select should take option

give two more option when we are selecting the countries like only and except , if you are putting any countries name inside the only then CountryStateSelect will fetch that countries only, and when you put the countries name with except at that time except that it should show all countries name.

Receiving uninitialized constant for CountryStateSelect for 3.0.3

I can no longer mount CountryStateSelect::Engine with 3.0.3? My rails is unable to locate the constant.....I'm using Rails 5.2 and ruby 2.4.4

NameError (uninitialized constant CountryStateSelect):

config/routes.rb:4:in block in <top (required)>' config/routes.rb:1:in <top (required)>'

routes.rb

mount CountryStateSelect::Engine => '/'

Rails cannot load the js file as well.

Feature to default select options

this is patch


   <%= f.input :test_country, label: "Country", collection: CountryStateSelect.countries_collection, selected:CountryStateSelect.countries_collection[229] %>

    <%= f.input :test_state, collection: CS.states(:us).values, selected: CS.states(:us)[:FL] %>

Looking for method which we can set by chosen itself

Provinces missing?

Hi, I see in the Readme a lot of references to "State / Province". So I thought this gem would provide provinces. But it does not seem to unless I am missing something? (I realise there seem to be differing interpretations of the word Province so it is understandable - e.g. Canada's states are referred to as Provinces)

Spain for example has 17 Autonomous Regions or States(e.g. Catalonia), 50 Provinces (e.g. Barcelona (also a city) - these seem to have the same name as the major city in the Province) and lots more cities. Apparently the provinces are more meaningful for the Spanish but I cannot seem to find them in your gem.

Is there some method for doing this or does it not exist?

Added demo app link

Need to create one demo app from where any one can see how this gem work , we can deploy our dummy app in to heroku and add that link to about page or some where in wikki

City bugs

@arvindvyas

Here are the bugs that I was referring to in the other post.

1. When you change the country, the options under city should change to the first state's cities.

Example: If you start out on United States, Alaska shows up.

Switch to Canada and Alberta shows up under the new states.

That's correct.

BUT ... the cities from Alaska still appear under the cities drop down after you have switched to Canada / Alberta. That isn't correct.

The minute that the state changes, it should automatically switch the cities to the new state you've selected.

To fix this, it will involve a fix to the country_state_select.js.erb file. You're going to need to add a trigger of some sort to make the cities update based upon the change of the state / province.

2. For some reason, the #collect_cities method in returns cities correctly to the controller but nowhere else.

I cannot figure out why CS.cities can return the correct cities array when it's called within the controller but returns an empty set [] when it's called from within the view.

By contrast, CountryStateSelect.collect_states(f.object.test_country) works the same in either location.

I've spent hours troubleshooting this issue without any luck.

I didn't see anything wrong with the collect_cities method, but that's weird behavior!

javascript isnt working on rails 5

Im using rails 5 and when i select my country i would like to get the cities of the selected country but i cant do it... i tried it in many ways already and nothing is working properly
thanks

New instructions please

The instructions for installing and implementing this gem appear out of date. Please provide more up to date, clear and specific guidance on installing and using this gem, particularly for those on Rails 4 and 5.

possibility to update to rails 5?

Bundler could not find compatible versions for gem "rails":
In snapshot (Gemfile.lock):
rails (= 5.1.2)

In Gemfile:
rails

country_state_select was resolved to 2.0.0, which depends on
  rails (>= 3.0)

Compass outdated dependency problem

The latest build appears to depend on compass-rails (~> 2.0.4) which is badly outdated and won't install on my Rails 5 application. Is it possible to update the dependency?

Updateding the js file which I want to mange from the gem

$( document ).ready(function() {
arrayCountry = ["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola",
"Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria",
"Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin",
"Bermuda", "Bhutan", "Bolivia, Plurinational State of", "Bonaire, Sint Eustatius and Saba", "Bosnia and Herzegovina",
"Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia",
"Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
"Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba",
"Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt","El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia", "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece",
"Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard Island and McDonald Islands", "Holy See (Vatican City State)",
"Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran, Islamic Republic of", "Iraq",
"Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya",
"Kiribati", "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", "Kyrgyzstan",
"Lao People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya",
"Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Macedonia, The Former Yugoslav Republic Of",
"Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique",
"Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of",
"Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru",
"Nepal", "Netherlands", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau",
"Palestinian Territory, Occupied", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines",
"Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation",
"Rwanda", "Saint Barthelemy", "Saint Helena, Ascension and Tristan da Cunha", "Saint Kitts and Nevis", "Saint Lucia",
"Saint Martin (French Part)", "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino",
"Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore",
"Sint Maarten (Dutch Part)", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa",
"South Georgia and the South Sandwich Islands", "South Sudan", "Spain", "Sri Lanka", "Sudan", "Suriname",
"Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic",
"Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Timor-Leste",
"Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan",
"Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom",
"United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu",
"Venezuela, Bolivarian Republic of", "Viet Nam", "Virgin Islands, British", "Virgin Islands, U.S.",
"Wallis and Futuna", "Western Sahara", "Yemen", "Zambia", "Zimbabwe"]

$( "#country_id").change(function() {
var state = $('#country_id option:selected').text()
var indian_state = {
'AP' : 'Andhra Pradesh',
'AR' : 'Arunachal Pradesh',
'AS' : 'Assam',
'BR' : 'Bihar',
'CT' : 'Chhattisgarh',
'GA' : 'Goa',
'GJ' : 'Gujarat',
'HR' : 'Haryana',
'HP' : 'Himachal Pradesh',
'JK' : 'Jammu & Kashmir',
'JH' : 'Jharkhand',
'KA' : 'Karnataka',
'KL' : 'Kerala',
'MP' : 'Madhya Pradesh',
'MH' : 'Maharashtra',
'MN' : 'Manipur',
'ML' : 'Meghalaya',
'MZ' : 'Mizoram',
'NL' : 'Nagaland',
'OR' : 'Odisha',
'PB' : 'Punjab',
'RJ' : 'Rajasthan',
'SK' : 'Sikkim',
'TN' : 'Tamil Nadu',
'TR' : 'Tripura',
'UK' : 'Uttarakhand',
'UP' : 'Uttar Pradesh',
'WB' : 'West Bengal',
'AN' : 'Andaman & Nicobar',
'CH' : 'Chandigarh',
'DN' : 'Dadra and Nagar Haveli',
'DD' : 'Daman & Diu',
'DL' : 'Delhi',
'LD' : 'Lakshadweep',
'PY' : 'Puducherry',
}

var usa_state = {
'AL' :"Alabama",
'AK' :"Alaska",
'AZ' :"Arizona",
'AR' :"Arkansas",
'CA' :"California",
'CO' :"Colorado",
'CT' :"Connecticut",
'DE' :"Delaware",
'DC' :"District Of Columbia",
'FL' :"Florida",
'GA' :"Georgia",
'HI' :"Hawaii",
'ID' :"Idaho",
'IL' :"Illinois",
'IN' :"Indiana",
'IA' :"Iowa",
'KS' :"Kansas",
'KY' :"Kentucky",
'LA' :"Louisiana",
'ME' :"Maine",
'MD' :"Maryland",
'MA' :"Massachusetts",
'MI' :"Michigan",
'MN' :"Minnesota",
'MS' :"Mississippi",
'MO' :"Missouri",
'MT' :"Montana",
'NE' :"Nebraska",
'NV' :"Nevada",
'NH' :"New Hampshire",
'NJ' :"New Jersey",
'NM' :"New Mexico",
'NY' :"New York",
'NC' :"North Carolina",
'ND' :"North Dakota",
'OH' :"Ohio",
'OK' :"Oklahoma",
'OR' :"Oregon",
'PA' :"Pennsylvania",
'RI' :"Rhode Island",
'SC' :"South Carolina",
'SD' :"South Dakota",
'TN' :"Tennessee",
'TX' :"Texas",
'UT' :"Utah",
'VT' :"Vermont",
'VA' :"Virginia",
'WA' :"Washington",
'WV' :"West Virginia",
'WI' :"Wisconsin",
'WY' :"Wyoming"
}

var canadan_state = {
"BC" : "British Columbia",
"ON" : "Ontario",
"NL" : "Newfoundland and Labrador",
"NS" : "Nova Scotia",
"PE" : "Prince Edward Island",
"NB" : "New Brunswick",
"QC" : "Quebec",
"MB" : "Manitoba",
"SK" : "Saskatchewan",
"AB" : "Alberta",
"NT" : "Northwest Territories",
"NU" : "Nunavut",
"YT" : "Yukon Territory"
}

var uk_state = {
'GSY' : "Guernsey",
'JSY' : "Jersey",
'BDG' : "Barking and Dagenham",
'BNE' : "Barnet",
'BNS' : "Barnsley",
'BAS' : "Bath and North East Somerset",
'BDF' : "Bedfordshire",
'BEX' : "Bexley",
'BIR' : "Birmingham",
'BBD' : "Blackburn with Darwen",
'BPL' : "Blackpool",
'BOL' : "Bolton",
'BMH' : "Bournemouth",
'BRC' : "Bracknell Forest",
'BRD' : "Bradford",
'BEN' : "Brent",
'BNH' : "Brighton and Hove",
'BST' : "Bristol City of",
'BRY' : "Bromley",
'BKM' : "Buckinghamshire",
'BUR' : "Bury",
'CLD' : "Calderdale",
'CAM' : "Cambridgeshire",
'CMD' : "Camden",
'CHS' : "Cheshire",
'CON' : "Cornwall",
'COV' : "Coventry (West Midlands district)",
'CRY' : "Croydon",
'CMA' : "Cumbria",
'DAL' : "Darlington",
'DER' : "Derby",
'DBY' : "Derbyshire",
'DEV' : "Devon",
'DNC' : "Doncaster",
'DOR' : "Dorset",
'DUD' : "Dudley (West Midlands district)",
'DUR' : "Durham",
'EAL' : "Ealing",
'ERY' : "East Riding of Yorkshire",
'ESX' : "East Sussex",
'ENF' : "Enfield",
'ESS' : "Essex",
'GAT' : "Gateshead (Tyne & Wear district)",
'GLS' : "Gloucestershire",
'GRE' : "Greenwich",
'HCK' : "Hackney",
'HAL' : "Halton",
'HMF' : "Hammersmith and Fulham",
'HAM' : "Hampshire",
'HRY' : "Haringey",
'HRW' : "Harrow",
'HPL' : "Hartlepool",
'HAV' : "Havering",
'HEF' : "Herefordshire County of",
'HRT' : "Hertfordshire",
'HIL' : "Hillingdon",
'HNS' : "Hounslow",
'IOW' : "Isle of Wight",
'IOS' : "Isles of Scilly",
'ISL' : "Islington",
'KEC' : "Kensington and Chelsea",
'KEN' : "Kent",
'KHL' : "Kingston upon Hull City of",
'KTT' : "Kingston upon Thames",
'KIR' : "Kirklees",
'KWL' : "Knowsley",
'LBH' : "Lambeth",
'LAN' : "Lancashire",
'LDS' : "Leeds",
'LCE' : "Leicester",
'LEC' : "Leicestershire",
'LEW' : "Lewisham",
'LIN' : "Lincolnshire",
'LIV' : "Liverpool",
'LND' : "London City of",
'LUT' : "Luton",
'MAN' : "Manchester",
'MDW' : "Medway",
'MRT' : "Merton",
'MDB' : "Middlesbrough",
'MIK' : "Milton Keynes",
'NET' : "Newcastle upon Tyne",
'NWM' : "Newham",
'NFK' : "Norfolk",
'NEL' : "North East Lincolnshire",
'NLN' : "North Lincolnshire",
'NSM' : "North Somerset",
'NTY' : "North Tyneside",
'NYK' : "North Yorkshire",
'NTH' : "Northamptonshire",
'NBL' : "Northumberland",
'NGM' : "Nottingham",
'NTT' : "Nottinghamshire",
'OLD' : "Oldham",
'OXF' : "Oxfordshire",
'PTE' : "Peterborough",
'PLY' : "Plymouth",
'POL' : "Poole",
'POR' : "Portsmouth",
'RDG' : "Reading",
'RDB' : "Redbridge",
'RCC' : "Redcar and Cleveland",
'RIC' : "Richmond upon Thames",
'RCH' : "Rochdale",
'ROT' : "Rotherham",
'RUT' : "Rutland",
'SHN' : "St Helens",
'SLF' : "Salford",
'SAW' : "Sandwell",
'SFT' : "Sefton",
'SHF' : "Sheffield",
'SHR' : "Shropshire",
'SLG' : "Slough",
'SOL' : "Solihull",
'SOM' : "Somerset",
'SGC' : "South Gloucestershire",
'STY' : "South Tyneside",
'STH' : "Southampton",
'SOS' : "Southend-on-Sea",
'SWK' : "Southwark",
'STS' : "Staffordshire",
'SKP' : "Stockport",
'STT' : "Stockton-on-Tees",
'STE' : "Stoke-on-Trent",
'SFK' : "Suffolk",
'SND' : "Sunderland",
'SRY' : "Surrey",
'STN' : "Sutton",
'SWD' : "Swindon",
'TAM' : "Tameside",
'TFW' : "Telford and Wrekin",
'THR' : "Thurrock",
'TOB' : "Torbay",
'TWH' : "Tower Hamlets",
'TRF' : "Trafford",
'WKF' : "Wakefield",
'WLL' : "Walsall",
'WFT' : "Waltham Forest",
'WND' : "Wandsworth",
'WRT' : "Warrington",
'WAR' : "Warwickshire",
'WBK' : "West Berkshire",
'WSX' : "West Sussex",
'WSM' : "Westminster",
'WGN' : "Wigan",
'WIL' : "Wiltshire",
'WNM' : "Windsor and Maidenhead",
'WRL' : "Wirral",
'WOK' : "Wokingham",
'WLV' : "Wolverhampton",
'WOR' : "Worcestershire",
'YOR' : "York",
'ANT' : "Antrim",
'ARD' : "Ards",
'ARM' : "Armagh",
'BLA' : "Ballymena",
'BLY' : "Ballymoney",
'BNB' : "Banbridge",
'BFS' : "Belfast",
'CKF' : "Carrickfergus",
'CSR' : "Castlereagh",
'CLR' : "Coleraine",
'CKT' : "Cookstown",
'CGV' : "Craigavon",
'DRY' : "Derry",
'DOW' : "Down",
'DGN' : "Dungannon and South Tyrone",
'FER' : "Fermanagh",
'LRN' : "Larne",
'LMV' : "Limavady",
'LSB' : "Lisburn",
'MFT' : "Magherafelt",
'MYL' : "Moyle",
'NYM' : "Newry and Mourne",
'NTA' : "Newtownabbey",
'NDN' : "North Down",
'OMH' : "Omagh",
'STB' : "Strabane",
'ABE' : "Aberdeen",
'ABD' : "Aberdeenshire",
'ANS' : "Angus",
'AGB' : "Argyll and Bute",
'CLK' : "Clackmannanshire",
'DGY' : "Dumfries and Galloway",
'DND' : "Dundee",
'EAY' : "East Ayrshire",
'EDU' : "East Dunbartonshire",
'ELN' : "East Lothian",
'ERW' : "East Renfrewshire",
'EDH' : "Edinburgh",
'ELS' : "Eilean Siar",
'FAL' : "Falkirk",
'FIF' : "Fife",
'GLG' : "Glasgow",
'HLD' : "Highland",
'IVC' : "Inverclyde",
'NAY' : "North Ayrshire",
'NLK' : "North Lanarkshire",
'ORK' : "Orkney Islands",
'PKN' : "Perth and Kinross",
'MLN' : "Midlothian",
'MRY' : "Moray",
'RFW' : "Renfrewshire",
'SCB' : "Scottish Borders The",
'ZET' : "Shetland Islands",
'SAY' : "South Ayrshire",
'SLK' : "South Lanarkshire",
'STG' : "Stirling",
'WDU' : "West Dunbartonshire",
'WLN' : "West Lothian",
'BGW' : "Blaenau Gwent",
'BGE' : "Bridgend",
'CAY' : "Caerphilly",
'CRF' : "Cardiff",
'CMN' : "Carmarthenshire",
'CGN' : "Ceredigion",
'CWY' : "Conwy",
'DEN' : "Denbighshire",
'FLN' : "Flintshire",
'GWN' : "Gwynedd",
'AGY' : "Isle of Anglesey",
'MTY' : "Merthyr Tydfil",
'MON' : "Monmouthshire",
'NTL' : "Neath Port Talbot",
'NWP' : "Newport",
'PEM' : "Pembrokeshire",
'POW' : "Powys",
'RCT' : "Rhondda Cynon Taf",
'SWA' : "Swansea",
'TOF' : "Torfaen",
'VGL' : "Vale of Glamorgan",
'WRX' : "Wrexham",
'ABD' : 'Aberdeenshire',
'ALD' : 'Alderney',
'AGY' : 'Anglesey (Isle of)',
'ANS' : 'Angus',
'AGB' : 'Argyll and Bute',
'AYR' : 'Ayrshire',
'BAN' : 'Banffshire',
'BDF' : 'Bedfordshire',
'BRK' : 'Berkshire',
'BEW' : 'Berwickshire',
'BGW' : 'Blaenau Gwent',
'BOR' : 'Borders',
'BGE' : 'Bridgend',
'BST' : 'Bristol',
'BKM' : 'Buckinghamshire',
'CAY' : 'Caerphilly',
'CAI' : 'Caithness',
'CAM' : 'Cambridgeshire',
'CRF' : 'Cardiff',
'CMN' : 'Carmarthenshire',
'CEN' : 'Central Scotland',
'CGN' : 'Ceredigion',
'CHI' : 'Channel Islands',
'CHS' : 'Cheshire',
'CLK' : 'Clackmannanshire',
'CWD' : 'Clwyd',
'CWY' : 'Conwy',
'CON' : 'Cornwall',
'ANT' : 'County Antrim',
'ARM' : 'County Armagh',
'DOW' : 'County Down',
'DUR' : 'County Durham',
'TYR' : 'County Tyrone',
'CMA' : 'Cumbria',
'DEN' : 'Denbighshire',
'DER' : 'Derbyshire',
'DEV' : 'Devon',
'DOR' : 'Dorset',
'DGY' : 'Dumfries & Galloway',
'DNB' : 'Dunbartonshire',
'DYD' : 'Dyfed',
'ELN' : 'East Lothian',
'ERY' : 'East Riding of Yorkshire',
'ESX' : 'East Sussex',
'ESS' : 'Essex',
'FER' : 'Fermanagh',
'FIF' : 'Fife',
'FLN' : 'Flintshire',
'GLA' : 'Glamorgan',
'GLS' : 'Gloucestershire',
'GMP' : 'Grampian',
'GSY' : 'Guernsey',
'GNT' : 'Gwent',
'GWN' : 'Gwynedd',
'HAM' : 'Hampshire',
'HEF' : 'Herefordshire',
'HRT' : 'Hertfordshire',
'HLD' : 'Highlands',
'INV' : 'Inverness-shire',
'IOM' : 'Isle of Man',
'IOW' : 'Isle of Wight',
'JSY' : 'Jersey',
'KEN' : 'Kent',
'KCD' : 'Kincardineshire',
'KRS' : 'Kinross-shire',
'KKD' : 'Kirkcudbrightshire',
'LKS' : 'Lanarkshire',
'LAN' : 'Lancashire',
'LEI' : 'Leicestershire',
'LIN' : 'Lincolnshire',
'LND' : 'London',
'LDY' : 'Londonderry',
'GTM' : 'Manchester (Greater)',
'MSY' : 'Merseyside',
'MTY' : 'Merthyr Tydfil',
'MDX' : 'Middlesex',
'MLN' : 'Midlothian',
'MON' : 'Monmouthshire',
'MOR' : 'Moray',
'NAI' : 'Nairnshire',
'NTL' : 'Neath Port Talbot',
'NWP' : 'Newport',
'NFK' : 'Norfolk',
'NYK' : 'North Yorkshire',
'NTH' : 'Northamptonshire',
'NBL' : 'Northumberland',
'NTT' : 'Nottinghamshire',
'OKI' : 'Orkney',
'OXF' : 'Oxfordshire',
'PEE' : 'Peeblesshire',
'PEM' : 'Pembrokeshire',
'PER' : 'Perthshire',
'POW' : 'Powys',
'RFW' : 'Renfrewshire',
'RCT' : 'Rhondda Cynon Taff',
'ROC' : 'Ross and Cromarty',
'ROX' : 'Roxburghshire',
'SEL' : 'Selkirkshire',
'SHI' : 'Shetland',
'SHR' : 'Shropshire',
'SOM' : 'Somerset',
'SYK' : 'South Yorkshire',
'STS' : 'Staffordshire',
'STI' : 'Stirlingshire',
'STD' : 'Strathclyde',
'SFK' : 'Suffolk',
'SRY' : 'Surrey',
'SUT' : 'Sutherland',
'SWA' : 'Swansea',
'TAY' : 'Tayside',
'TOF' : 'Torfaen',
'TWR' : 'Tyne & Wear',
'WAR' : 'Warwickshire',
'WLN' : 'West Lothian',
'WMD' : 'West Midlands',
'SXW' : 'West Sussex',
'WYK' : 'West Yorkshire',
'WIS' : 'Western Isles',
'WIG' : 'Wigtownshire',
'WIL' : 'Wiltshire',
'WOR' : 'Worcestershire',
'WRX' : 'Wrexham'
}

switch ( state ) {
case "India":
default_state = indian_state
break
case "United Kingdom":
default_state = uk_state
break;
case "Canada":
default_state = canadan_state
break;
case "United States":
default_state = usa_state
break;
default:
alert( "here required to add one input box" );
}
var s = $(''); for(var val in default_state) { $('', {value: val, text: default_state[val]}).appendTo(s); } $('#second_select').html(s); // or wherever it should be }); });

JavaScript: CountryStateSelect is not defined

Hello,
I would like to start by saying thank you for developing a gem with this functionality. I have followed the process to integrate your Gem, however, my app does not recognize the CountryStateSelect function in JavaScript.

I could not find much documentation, any help resolving this issue would be appreciated.

Will it include i18?

Hello, I am testing the gem. Great one. Thanks

Could not found any reference on it to locales. My locale is es: and is not working.

Will the gem include i18 for different locales?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.