mrmarkfrench / country-select-js

A quick jQuery-based country picker based on https://github.com/Bluefieldscom/intl-tel-input.git
MIT License
282 stars 105 forks source link

How to modify the name of a country? #67

Closed MoradHamdy closed 3 years ago

MoradHamdy commented 4 years ago

Assume i have this HTML code:

<div class="list-select-options">
    <input type="text" id="country">
    <input type="hidden" id="country_code">
    <i class="fa fa-sort"></i>
</div><!-- .list-select-options end -->

And this js code:

$("#country").countrySelect({
    defaultCountry: "gb",
    onlyCountries: ['eg','gb'],
    preferredCountries: false,
    responsiveDropdown: true
});

So how to change for example United Kingdom to England?

img-59

Hujjat commented 4 years ago

I would be easy to add Currency instead of Country name too. I'm looking forward for the feature to modify the default name.

mrmarkfrench commented 4 years ago

England is not a country (despite the UK government calling it that out of tradition), it's an administrative region of the country named the United Kingdom.

mrmarkfrench commented 4 years ago

That said, I'd be happy to see a pull request to allow a client to pass in their own JSON list of "country" values. This would allow you to rename things as you saw fit, to use incorrect names, to eliminate the English (or non-English) version of the country name, or to replace the country name with something else, like currency.

iamkarsoft commented 4 years ago

How do you get the full name of a country? rather than the shortcode

mrmarkfrench commented 4 years ago

How do you get the full name of a country? rather than the shortcode

@iamkarsoft, the two inputs are both submitted with the form. So the first one will have the full name of the country, and the one with "_code" at the end of the ID will have the short code.

iamkarsoft commented 4 years ago

@mrmarkfrench i can now get the id. but I want to change the ITI default plugin country based on when the country is changed. don't know what to attach the handler to ? is there a way to solve this?

mrmarkfrench commented 4 years ago

If you attach an .on("change") handler to the "_code" field, it will fire when that field is updated (and not every keystroke if the user types part of a name into the country name field). That should let you make any changes you want when the user selects a country.

iamkarsoft commented 4 years ago

Is there a way to show the country with the corresponding flag on another page after collecting the data? @mrmarkfrench

mrmarkfrench commented 4 years ago

You could create an instance of the input, set the default value to the selected country, and leave only that country on the list, @iamkarsoft.

mrmarkfrench commented 3 years ago

The latest version (v2.1.0) now allows you to set the localized name of a country (see the localizedCountries option, documented on the README). This will allow you to override the names of countries you wish to change.