Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: empty country selection #11

Open
vektor330 opened this issue Aug 7, 2015 · 12 comments
Open

Feature request: empty country selection #11

vektor330 opened this issue Aug 7, 2015 · 12 comments

Comments

@vektor330
Copy link

One more for today :)
It seems to me there is no straightforward way to "clear" the selection, so that after submitting the form the country value is "empty". The same goes for starting without any country selected.

Am I missing something? If not, how hard would it be to add this possibility?

@mrmarkfrench
Copy link
Owner

Hmm. Not sure. The way it's built, it definitely expects there to be a country selected. Usually this is handled by setting a default country, or by selecting one or more "preferred" countries to appear at the top of the list, and relying on it to just select the first one by default.

If you have a suggestion on how you think this should be handled, I'd be interested to see it. I think that this should be optional behavior, but the ability to have no country selected is a perfectly valid choice in some use cases.

@vektor330
Copy link
Author

I would keep the default behavior just the way it's today. But let's say there is an option "allowsEmpty" that makes it possible to have defaultCountry empty as well, and if you say "selectCountry", "" then this clears the selection as well. Empty county would then mean empty result from getSelectedCountryData and empty value in the associated _code field.

@mrmarkfrench
Copy link
Owner

Yes, all of that makes sense. The part that I think is actually the wrinkle is around the display of the flag. What is shown in the spot where the flag usually is if nothing is selected? What prompts the user that if they click there, a list of flags and country names will drop down for them to select from?

I think leaving it entirely blank doesn't give the user the right information to interact with it. Maybe an "empty" flag would do the trick. Something like this: https://sophiesensei.files.wordpress.com/2014/10/blankflag.png?w=705

@vektor330
Copy link
Author

Empty flag makes sense, perhaps a globe icon would convey the same meaning.

@aaronfischer
Copy link

Did anything end up coming from this?

I definitely have a use-case for needing an empty or null defaultCountry on initialization.
(Can @mrmarkfrench think of any other way of doing this?)

@mrmarkfrench
Copy link
Owner

@aaronfischer I'd be happy to accept a pull request.

@baberuth22
Copy link

I'd like to have an empty country as well. Are there any solutions that can be implemented immediately? Instead of an empty flag, I think the text 'Select a Country' would be most informative.

@j77esus
Copy link

j77esus commented Mar 31, 2017

Hello!
+1 👍 to "Select a Country" text :) maybe with a down arrow instead of a flag

@cnsgithub
Copy link

Easy workaround who needs this feature:

  • Modifly flags sprite if you want an icon for your custom selection
  • add CSS: .country-select .xa{background-position:-208px -154px}
    .country-select .xn{background-position:-208px -165px}
  • add custom value:
      {
		n: "All",
		i: "xa"
	}

{
		n: "None",
		i: "xn"
	}

But obviously a proper solution for possible use-cases

"No country" , or "All countries" would be useful

@kilinkis
Copy link

kilinkis commented Aug 23, 2017

I would love to see this as well

@cnsgithub thanks for your effort, but how do you add the custom values?

@cnsgithub
Copy link

cnsgithub commented Sep 4, 2017

I don't understand. Just add them to the variable (modify the countrySelect file)

var allCountries

@vipertecpro
Copy link

I had to use js instead of min.js...Following is workaround suggested above and it works fine with me :-

$(".country_selector").countrySelect({
       defaultCountry: "xn",
   });
var allCountries = $.each([
        {
            n: "PLease Select the country",
            i: "xn"
        },...............
 ], function(i, c) {
		c.name = c.n;
		c.iso2 = c.i;
		delete c.n;
		delete c.i;
	});

asdasd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants