Giter Club home page Giter Club logo

geodatasource / country-region-dropdown-menu Goto Github PK

View Code? Open in Web Editor NEW
60.0 5.0 35.0 3.82 MB

A dropdown menu created with javascript that allows user to implement country-region dropdown list effortlessly.

Home Page: http://www.geodatasource.com/software/country-region-dropdown-menu

License: MIT License

HTML 6.66% CSS 44.90% JavaScript 46.10% Java 1.17% PHP 1.17%
country-region-dropdown country-region-data geodatasource country-selector region-selector region-field selector

country-region-dropdown-menu's Introduction

Country-Region DropDown Menu

This javascript enables you to implement a country-region dropdown menu with ease. It is just as simple as to enter the pre-defined class name and attribute into the dropdown control (HTML select input box) to make them work. After that, the region dropdown will be automatically repopluated upon the selection of country name.

This plugin uses the ISO defined name for the display, namely ISO3166-1 (for Country Name) and ISO3166-2 (for Region Name).

  • Total of 247 country name supported (except Bouvet Island and Heard Island and Mcdonald Islands, which have no region/subdivision defined)
  • Please visit ISO3166-2 Subdivision Code to learn more about the ISO3166-2 supported.

Multilingual Display Supported

This plugin equipped with multiple languages for country and region name display. Please see the below of the supported languages.

Language code Language Name
ar Arabic Demo
cs Czech Demo
da Danish Demo
de German Demo
en English Demo
es Spanish Demo
et Estonian Demo
fi Finnish Demo
fr French Demo
ga Irish Demo
it Italian Demo
ja Japanese Demo
ko Korean Demo
ms Malay Demo
nl Dutch Demo
pt Portuguese Demo
ru Russian Demo
sv Swedish Demo
tr Turkish Demo
vi Vietnamese Demo
zh-cn Chinese Simplified Demo
zh-tw Chinese Traditional Demo

City DropDown Supported

Please take a look on How to add City DropDown to Country-Region DropDown Menu tutorial to learn more about how City DropDown added.

Plugins

Demo

Country-Region DropDown Menu Demo 1

Country-Region DropDown Menu Demo 2

Please check on demo page to have a clearer picture about how it works.

Demo on JSFiddle

Please try out the demo on JSFiddle page.

CDN of Libraries

Usage

    <html>
      <head>
        <meta charset="UTF-8">

        <!-- link for jquery style -->
        <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
        <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
        <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">

        <script src="assets/js/geodatasource-cr.min.js"></script>
        <link rel="stylesheet" href="assets/css/geodatasource-countryflag.css">

        <!-- link for semantic-ui style -->
        <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js" integrity="sha512-dqw6X88iGgZlTsONxZK9ePmJEFrmHwpuMrsUChjAw1mRUhUITE5QU9pkcSox+ynfLhL15Sv2al5A0LVyDCmtUw==" crossorigin="anonymous"></script>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css" integrity="sha512-8bHTC73gkZ7rZ7vpqUQThUDhqcNFyYi2xgDgPDHc+GXVGHXq+xPjynxIopALmOPqzo9JZj0k6OqqewdGO3EsrQ==" crossorigin="anonymous" />

        <!-- link to languages po files -->
        <link rel="gettext" type="application/x-po" href="languages/en/LC_MESSAGES/en.po" />
        <script type="text/javascript" src="assets/js/Gettext.js"></script>
      </head>
      <body>

        <div>
            Country: <select class="gds-cr" country-data-region-id="gds-cr-one" data-language="en"></select>

            Region: <select id="gds-cr-one" ></select>
        </div>

        <div>
            Country: <select class="gds-cr" country-data-region-id="gds-cr-two" data-language="en" country-data-default-value="US" ></select>

            Region: <select id="gds-cr-two" region-data-default-value="California" ></select>
        </div>

        <div>
            Country: <select class="gds-cr gds-countryflag" country-data-region-id="gds-cr-three" data-language="en"></select>

            Region: <select id="gds-cr-three"></select>
        </div>

        <div>
            Country: <div class="ui fluid search selection dropdown gds-cr-semantic" country-data-region-id="gds-cr-four" data-language="en"></div>

            Region: <select id="gds-cr-four"></select>
        </div>

        <div>
            Country: <input class="gds-cr-autocomplete" country-data-region-id="gds-cr-five" data-language="en">

            Region: <input class="gds-cr-five-autocomplete" id="gds-cr-five">
        </div>

        <div>
            Country: <select class="gds-cr" country-data-region-id="gds-cr-six" data-language="en" country-include="US,GB,DE,FR,IT,NL"></select>

            Region: <select id="gds-cr-six" ></select>
        </div>

      </body>
    </html>

Bootstrap with cdnjs Usage

If you are using Twitter Bootstrap with cdnjs, you may refer to the below example for the implementation.

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>Country-Region DropDown Menu</title>

        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/country-region-dropdown-menu/2.4.1/js/geodatasource-cr.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js" type="text/javascript"></script>
        <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/country-region-dropdown-menu/2.4.1/css/geodatasource-countryflag.min.css">

        <link rel="gettext" type="application/x-po" href="languages/en/LC_MESSAGES/en.po" />
        <script type="text/javascript" src="assets/js/Gettext.js"></script>
    </head>
    <body>
        <div class="container">
            <div class="row">
                <div class="col-md-12 text-center" style="margin-bottom:40px;">
                    <h2>Country-Region DropDown Menu</h2>
                </div>
                <div class="col-md-12">
                    <form class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Country</label>
                            <div class="col-sm-10">
                                <select class="form-control gds-cr gds-countryflag" country-data-region-id="gds-cr-1" data-language="en"></select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="gds-cr-1" class="col-sm-2 control-label">Region</label>
                            <div class="col-sm-10">
                                <select class="form-control" id="gds-cr-1"></select>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </body>
    </html>

Node.js Usage

The following steps show how to use the dropdown menu in Express Web Framework:

  1. Install the module by npm install country-region-dropdown-menu
  2. Copy geodatasource-cr.min.js script and Gettext.js script to /public/javascripts/ directory.
  3. Copy geodatasource-countryflag.css stylesheet to /public/stylesheets/ directory.
  4. Copy geodatasource-countryflag.png image to /public/img/ directory.
  5. Copy languages folder to /public/ directory.
  6. Include the script in the jade file by script(src='/javascripts/geodatasource-cr.min.js')
  7. Include the script in the jade file by script(src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"))
  8. Include the script in the jade file by script(src="//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js")
  9. Include the link in the jade file by link(rel='stylesheet' href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css")
  10. Include the link in the jade file by link(rel='stylesheet' href='stylesheets/geodatasource-countryflag.css')
  11. Include the link in the jade file by link(rel='gettext' type='application/x-po' href='languages/en/LC_MESSAGES/en.po')
  12. Include the script in the jade file by script(src='/javascripts/Gettext.js')
  13. Code for implementation:
    |Country:
    select.gds-cr(country-data-region-id="gds-cr-one",data-language="en").gds-countryflag
    |Region:
    select#gds-cr-one

Attributes

  • Country field must be given a class name as gds-cr whereas gds-cr-semantic for country field that using Semantic-UI whereas gds-cr-autocomplete for country field that using autocomplete input option.
  • gds-countryflag can be added to class name of country field to support country flag.
  • country-data-region-id is required in country field that contains the id of region field.
  • data-language is required in country field which use set the language used in both country and region data. Refer to multilingual section for language code supported.
  • country-data-default-value is optional in country field which use to set the default selected country value, it supports both ISO3166-1 alpha-2 Country Code and country full name.
  • country-include is optional in country field which use to set country dropdown with the specific countries, for example country-include="US,GB,DE,FR,IT,NL"
  • country-exclude is optional in country field which use to exclude the specific countries from the country dropdown , for example country-exclude="US,GB,DE,FR,IT,NL"
  • region-data-default-value is optional in region field which use set the default selected region value.

Country Flag Designs

The Country Flag is designed from IP2Location™ Country Flags https://www.ip2location.com/free/country-flags

  • Square Country Flag with <link rel="stylesheet" href="assets/css/geodatasource-countryflag.css"> Square Country Flag
  • Round Country Flag with <link rel="stylesheet" href="assets/css/geodatasource-countryflag-round.css"> Round Country Flag
  • Bended Square Country Flag with <link rel="stylesheet" href="assets/css/geodatasource-countryflag-square-bended.css"> Marker Country Flag
  • Rounded Square Country Flag with <link rel="stylesheet" href="assets/css/geodatasource-countryflag-square-rounded.css"> Marker Country Flag
  • Shadow Square Country Flag with <link rel="stylesheet" href="assets/css/geodatasource-countryflag-square-shadow.css"> Marker Country Flag
  • Flag logo Country Flag with <link rel="stylesheet" href="assets/css/geodatasource-countryflag-flag.css"> Flag logo Country Flag

Sample page

Please refer to example-default.html file.

Support

Email: [email protected]
URL: https://www.geodatasource.com

country-region-dropdown-menu's People

Contributors

chrislim2888 avatar geodatasource 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

Watchers

 avatar  avatar  avatar  avatar  avatar

country-region-dropdown-menu's Issues

Access selected country ID

I'm trying to access the selected country ID (the ISO standard, not the name) using the dropdown menu with semantic, but all I manage to retrieve via Javascript is the selected region's name.

Node.js / Angular Uses

Need informations how to use in angular 8/9 (Node.js)

|Country:
select.gds-cr(country-data-region-id="gds-cr-one",data-language="en").gds-countryflag
|Region:
select#gds-cr-one*

It's not ez to understand it's even not correspend to html code... Can some one make me see light about ways to use it ? thanks !

Bower Availability

First off, can I just say this is an absolutely fantastic resource, and thank you so much for open sourcing it.

Can I suggest adding this as to Bower as well as npm? I'm sure I'm not alone in using Bower for anything that needs to be bundled in with my site, and npm for all my build processes.

Flags class interfere with selection and page scrolling

Hello,
I have noticed when I chose the option with flags icons selection, I have a problem scrolling all countries selections to the very bottom of the selection field or the entire web page.
I am using Firefox v.67 on Ubuntu 18.04.2.
I have traced the cause of the issue is "class: gds-countryflag". When deleted, the selection and page scroll controls return (but flags are missing).
I was not able to correct this issue.
Also, is there any way to display a country flag at the selection bar, after choosing a country, next to the country name?
Sincerely,
Z-N

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.