GithubHelp home page GithubHelp logo

country-regions / country-region-selector Goto Github PK

View Code? Open in Web Editor NEW
250.0 250.0 113.0 966 KB

Dynamic country and region dropdowns for your forms.

Home Page: http://country-regions.github.io/country-region-selector/

License: MIT License

JavaScript 84.39% HTML 15.61%
country-codes country-selection country-selector region-selector

country-region-selector's Issues

Istanbul not delimited

In the list of "states" for Turkey, Istanbul is combined with the following list item, like so:
IstanbKahramanmaras

Select 2 compatibility

Hi, Im trying to make this work with select2 jquery plugin, all options get loaded and I even can search, the problem is that the region field doesnt update when changing the option, could you give me some advice? Thanks!

Set default country but not the region

Is there a way to set the default country, but not default region? The default country populates correctly, but the region just shows a "-" as the only selection.
I have tried setting the region select options with no data-default-value tag and also tried the following tags in the region select:
data-default-value="-"
data-default-value=""
I am on the latest version 0.3.6, and I did not see this in the examples. I can determine the default country based on ip address, but I don't know the region.

Added AngluarJS functionality - need some distro changes to make it official though.

This is the most comprehensive list that I have seen. Lets make it better though.

  1. I have written an angularJS components for this. But in order for users to only get what they need it would be best to separate the the country/city code list from the main repo. And then allow options for users to just grab updates to city/country codes as they happen. If you can do this I will post all the necessary code for the AngularJS implementation.

  2. Another issue for consistency is using two/three letter codes for regions/states - there are about 2 dozen that don't have 2 or 3 letter codes....those countries just have the city name and this is all. That poses a problem for Angular when building the $scopes needed for the select drop down menus. In order to fix this, I had to find all those country regions which didn't have a proper 2/3 letter code and basically make one up. In my app i only store the country or region codes...so if one doesn't exist it will break my implementation.

Aside from how I made up region/state codes, how else can this be addressed?

Dropdowns do not update when values are set in backend

If I set my country dropdown's value to "Canada" in the backend, the dropdown shows the selected country as "Canada", but the region dropdown still displays "-" as if a country hasn't been selected.

Update
To get the region dropdown to populate, I had to do this:

document.getElementById('country').dispatchEvent(new Event('change'));

Bad region name for Sor-Trondelag in Norway

I don't see what is wrong, but try to select Norway, then Sor-Trondelag.

It reads Sor- instead of Sor-Trondelag for whatever reason. The source code looks good and I can't spot the culprit, but something caps it. Any idea?

NPM Package

My project uses this through npm, but that's still on version 0.2.0 so I can't take advantage of the bug fixes for data that have come out in the that two builds. Could you update it?

South Africa province wrong

In the country data
["South Africa","ZA","Eastern Cape~EC|Free State~FS|Gauteng~GT|KwaZulu-Natal~NL|Limpopo~LP|Mpumalanga~MP|Northern~Cape~NC|North West~NW|Western Cape~WC"],

Northern~Cape~NC should be Northern Cape~NC

Angular 1.6 - select fields not updating model

Hi!
I have a problem updating my project from angular 1.4.x to 1.x (which is 1.6.6 by now). CRS used to work OK, but it stopped updating the model of the fields, while the country selector perfectly updates the state field.
Select boxes works OK when populated manually, populating them with CRS makes this stop working.

<select
    name="countries"
    id="countries"
    class="crs-country"
    data-default-value="{{countryDefault}}"
    data-region-id="states"
    required
    ng-model="forms.card.address.country"
    data-value="shortcode">
<select
    id="states"
    required
    ng-model="forms.card.address.state"
    data-value="shortcode">

Best way to convert country codes back to full name?

Thanks for this very useful tool. We're storing only country codes and region codes (when available) but for UI purposes want to show users the full names. I was hoping there might already exist a code -> fullName lookup object in the design. I noticed the source data lives in a separate repo, but it appears to be built into this repo rather than an npm dependency. Has anyone else solved this problem already (hopefully without having to duplicate data)?

Is it possible to 5th depth?

dear developer..

i likely interested with this domain. but i want to ask before.

i want at registration form, a country field, a city field, and sub disctrict, and sub-sub district.
is it possible to do that?

i am in indonesia, i want people can choose indonesia country, then it shows all indonesia's province, jakarta for example. then after i choose jakarta it should show all city under it like south-jakarta, west jakarta, east jakarta.

this i want exactly i want:

...

  1. Hungary
  2. Indonesia (level 1)
  • 2,1 Jakarta (level 2)
    ---2.1.1 South Jakarta (level 3)
    ---2.1.1.1 Mampang Prapatan (level 4)
    ---2.1.1.1.1 Kuningan Barat (level 5)
  1. India
    ...

that's look 5 depth. and of course it find to database table that we will provide before. in indonesia, it have 82.353 at level 5 (villages). and seems we need add all these villages to a database.

is it possible this plugin support this kind of feature? thank you verymuch :)

Pre built javascript file Error

WARNING in .//react-country-region-selector/dist/rcrs.js
Critical dependencies:
1:477-484 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
@ ./
/react-country-region-selector/dist/rcrs.js 1:477-484

Presetting data attribute via jquery

Hello.

Thanks for this fantastic control!

Is there a way I can set the selected country and/or region via jquery?

I have an order form with billing and shipping and would like to provide the user with a checkbox to copy billing as shipping details.

So far I have not been successful with getting any of this to work.

Example (hard-coded/watered down for ease of explanation):
$("#BillingCountry").attr('data-default-value', 'United States');
$("#BillingCountry").attr('default-value', 'United States');
$("#BillingCountry").attr('defaultvalue', 'United States');

etc. etc.

Your "pre-filling" examples work just fine but I'm looking to populate the selection dynamically NOT in the markup prior to page load as my page does not do any server postback between sections.

Thanks!

Ian

Dynamic trigger

How would one trigger the initialization function of country-region-selector on dynamically loaded content?

can't initialize select

when appending country city selector and trying crs.init() I got

crs.js:70 Uncaught TypeError: Cannot set property '0' of undefined
at _populateCountryFields (crs.js:70)
at Object._init [as init] (crs.js:45)
at addExtraActions (client.js:118)
at Object.success (scripts.js:325)
at i (jquery.min.js:4)
at Object.fireWith [as resolveWith] (jquery.min.js:4)
at z (jquery.min.js:6)
at XMLHttpRequest. (jquery.min.js:6)

``

data-default-value not set

How do I get the country dropdown to display "United States" by default, AND have it's value to match?

I have an on change event attached to the country selector.
When the page loads, however, when, in my $(document).ready, I use $("#myselector").val() the value is empty.

Now, I've set both: data-default-option="United States" and data-default-value="United States" but it seems like, although it sets the default option, it doesn't set the value.

If I don't set the data-default-option then the default item in the selector stays "Select country" even though I've set data-default-value.

In fact, if I click on the select box and choose the default, it still has no value. The only time a value is set is when I select something from the list besides the default at the first position.

Am I missing something?

Solution : window.crs.populateRegionFields(countryElement, regionElement) **FOR "RELOADING" THE REGION SELECT**

Hello

I added 1 line of code in your plugin today and i wanted to "commit" my change here:

File:
jquery.crs.js (0.4.0)

Line 212:
(Added) populateRegionFields: _populateRegionFields

So I can call this specific row of code to update the Region Select after I'm setting the value via jQuery:

EXAMPLE
window.crs.init();
$.getJSON('//freegeoip.net/json/', function(result) {
$('#crs-country').val(result.country_code);
window.crs.populateRegionFields($('#crs-country')[0],$('#crs-region')[0]);
});

This Method will locate the current CountryCode from freegeoip.net and determine from which Country the Visitor is coming from and it will assign the value automatically to the Country Select and "repopulate" the Region Select with the current Country Select Value.

I hope I could help a little for others that run in to the same "issue" of a missing region reload method C:

Kind Regards

Mike of Creative-House.org

data-default-value in region

data-default-value in region does not work.
Can you please help.

Country Field

<select class="form-control crs-country" id="cube-wad__adr_country" label="Country" name="wad__adr_country" data-region-id="wad__adr_country" data-default-value="United States" data-default-option="...Choose" data-crs-loaded="true">

this field is pre-populated but not the region.

Region Field

<select class="form-control" id="wad__adr_country" label="State" name="wad__adr_state" required="" data-value="abbr" data-default-value="DC" data-blank-option="...Select Country">

Thank you for this library.

Add more cities

How to add more countries ? I'd like to add more cities in Bulgaria.
I try to edit something but without success. Even if i edit the names, the changes not made.

Sporadic issue - jquery.crs.js not running 80% of the time in a large project

I am making some modification on a large website which downloads a lot of JS file. This may have resulted in sporadic failure. To be explicit, the failure is the "select" tag with class "crs-country" is not populated at all. Digging into the issue, I found that the "_init" function is not being called every time.

I have found a workaround myself, namely to do the following:
1. Comment out: Line 9 to 21 and Line 469 to Line 474.
2. Comment out: Line 467 ==> "$(_init)" and replace it with "$( document ).ready(_init);"

This seems to have resolved my issue.

Typo in United Kingdom

In crs.js line 252: It says "ddlesbrough" instead of Middlesbrough.

By the way, what is the source for this data, and does it get updated?

Request: Prioritize certain countries at top of dropdown

If I rearrange the country select to have Canada and United States at the top of the list and then select Canada, the region select is populated with Afghanistan regions. This likely means the region select is populated based on selected country index instead of value.

let countries = document.getElementById('country');
let canada = countries.options[40];
let united_states = countries.options[235];
countries.remove(40);
countries.remove(235);
countries.add(canada, 1);
countries.add(united_states, 2);

Validating input

Given that this is being used on the client side and then data sent to the server, once on the server side, can I use this module in Node to validate the input data? How would I go about doing that?

Bootstrap modal closes automatically

I am using this inside a bootstrap modal. When I select a country the bootstrap modal closes automatically. I don't know whats happening. Please help

Not working

I have installed country-region-selector using below command

npm install country-region-selector --save

In my HTML I used it like this

<select  class="crs-country" data-region-id="ABC"></select>
<select id="ABC"></select>

but Countries are not showing in dropdown

data-default-value option seems not to work properly

The following code still show first region from the list (Alsace), not default value:

        <div class="form-group">
          <label for="country">Country</label>
                  <select name="country" class="form-control crs-country" data-region-id="one" data-value="shortcode" data-default-value="FR" data-show-default-option="false">
                  </select>
        </div>
        <div class="form-group">
          <label for="state">State or region</label>
                  <select name="state" class="form-control" id="one" data-default-value="Franche-Comté"  data-show-default-option="false">
                  </select>
        </div>

Blacklist Region - Puerto Rico

Puerto Rico is listed as a country and a region under the US. I'm not sure if this should be changed in the data file, or if some users might have a reason to use both variations. We are using this for export purposes, so we only want the country of Puerto Rico listed, and not the state under the US. Would it be possible to add the ability to blacklist a specific region in a country? I have already removed it from my data file, but I am looking at a better solution for when there are updates released in the future.

Feature: Disable first option in dropdowns.

As a feature: allow the first option in the a country/region select to have the disabled attribute set. This would force the user to make a country or region selection, and not allow the user to select the options "Select country" or "Select region". See an example of a select with the first option disabled: http://jsfiddle.net/s5Xy2/5/ to get the behavioural idea.

<select class="crs-country" data-region-id="region" data-value="shortcode"  data-crs-loaded="true">
    <option value="" disabled="disabled">Select country</option>
    <option value="AF">Afghanistan</option>
    <option value="AX">Åland Islands</option>
    <option value="AL">Albania</option>...

<select id="region">
     <option value="" disabled="disabled">Select region</option>...

Update grunt to allow custom build of subset of countries

There's the option baked in to allow whitelisting/blacklisting of countries, to control exactly what appears in the dropdown. This is handy, but it still means downloading the whole file.

Instead, we could add a grunt command to create a custom build that only bundles the specified countries, e.g.

grunt customBuild --countries=Canada,United States,Mexico

That would result in a WAAAAY smaller file.

Allow grouping of regions

After fixing the UK counties in another ticket, I found that I wanted to group the regions into <optgroups> for England, Scotland, Wales + Northern Ireland. This would be nice for other countries too, no doubt.

Feature Request: Define "preferred" countries that show up first in dropdown

As a user living in a certain country, I might want that country to be at the top of the dropdown so I don't have to scroll the entire alphabetical list to choose it.

As an ecommerce store manager, this might also help abandoment rates.

Maybe you could specify a list of countries you'd want to show up first?

Internationalization

Hi!

Thanks for stepping ahead to fill an obvious gap in the JS environment and building a fast and reliable country-region selector.

I'd need to be able to use the selector in an internationalized web app, and present the user with the country and region names according to their desired locale.

Are you planning to add this to country-region-selector? Any hints to do that myself?

Thanks!

Incorrect region code for Hakkaio, JP

My internationalization team alerted me to a region code issue:

Region code for "Hokkaido" is incorrect in Address. "Hokkaido" is one of the prefectures within Japan.
Currently, "Hokkaido" region code defaults to "04". However, the correct "Hokkaido" region code is "01". "04" is Miyagi.

United Kingdom regions corrupted

I'm not sure what happened, but the list of regions of the UK/GB is corrupted. Several county names are cut off or mangled in some way. I traced all the way to the first commit, and they are still wrong. I found a few correct versions, but it looks like a find and replace messed it up. If you still have your original source, perhaps you can correct it. Otherwise I'll try to track down the correct values to use.

Feature Request: 'Other' Select Option

Perhaps I'm missing it, but I don't see an option/way to force an 'other' option to lit up, say, a div or something else (with an input field) to allow for custom input.

It flies in the face of what this tool is trying to do, but it would be nice to have the option.

UK not recognized?

If I whitelist UK it does not work. If I use GB instead, then it works.

Why will UK not work?

How can I make it work?

Add country whitelist option

It would be helpful in some cases to only show a subset of the list of countries. Add a whitelist option to let users choose exactly which countries should be included in the country dropdown.

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.