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: State/Province Abbreviations #2
Comments
Agreed, that would be very nice. Good suggestion. |
👍 |
Problem about this one is that I don't think all country regions are able to be reduced to a 2-char abbreviations. But perhaps just an "abbreviate" option that limits them to whatever abbreviation is appropriate, according to the country. |
@benkeen Sounds like a sound idea to me, or perhaps 'alpha-2-code' or 'code' option would be a bit more explicit. |
Do you have a plan for how to approach this? We could get a spreadsheet of region codes for each country perhaps... Or use the wiki. |
How about this? https://github.com/benkeen/country-region-selector/blob/master/source/data-with-abbrev.js#L47 It's super simple: right now the If people are willing to do the (tedious!) task of updating that file, I can update the code to support it... [I can help out, too - but it may take some time for me to get to it]. |
Works great for me! I care most about US/AU/NZ/GB/BR/NO and a couple others, so I should be able to track down the data, then I'll fill in any others I can find easily. Hopefully @iapparatus will contribute some codes too and we can fill it out quickly. 👍 |
Nice, thanks @sventech! |
The regions we have for American Samoa are those from the tourist info, but the Wikipedia page lists these counties: |
you can hook up data from my fork guys, i changed some core functionality (defaulting to abbr data and such) and the regions/countries are a bit different, more ISOish i guess, so i didn't want to create a pull request. I will be using my modified version for my own needs - so feel free to pull my changes if you need to. |
This will be a great enhancement. Has code been written to support it? All I see is the data. |
@wobblymusic I think Ben is planning to implement it when the data is finished. He designed the data format to be handled by a trivial mod to his code, from what I understand. You're welcome to contribute -- you can just copy the data from sQu1rr / Aleksandr and make sure it is correctly formatted. There is a list of what countries remain to be done at the top of the file. |
Thanks for everyone whose chimed in - and for the pull requests! :) Clearly there's interest in this feature, so I'll work on this shortly, even though all the data isn't fully complete.
I think between these, it'll be okay to implement now without the full data set. Once this is in, I'll also try to devote a little time to adding in some as well. Be nice to get this sucker all wrapped up! |
That would be great. The second bullet, in particular, is how I imagined the feature would work. |
Hi all, I've just added this and released Couple of quick comments:
Let me know if anyone spots any problems! I'll leave this issue open a little while before closing it. |
Norway's listing has the name and abbreviation twice. Probably my fault. I've created a pull request. Thanks for implementing the feature! |
This is working great, Thank you so much! One small change that should probably be made to the README file. If you are using the data-default-value - optional. The default selected value in the region dropdown (e.g. "British Columbia", or "BC" if using the I apologizing for not implementing this myself, but I'm not very git-literate (I'm working on it!). |
Ah, good call! I'll make a note to update the doc tonight. |
Since this new version with the region abbreviations was posted, I'm having trouble adding a customization I had working in the previous version. I'm using this in conjuction with another function that requires the 2 letter country code as a parameter. When the country under crs is changed, I want to populate the region fields, but I also want to fire this other script. In the older version of crs, I put my function within Relatedly, I stupidly didn't save my customized old version and now I can't figure out how to grab the 2 letter country code for the selected country. Can someone help me with that as well? I don't want to use the country shortcode option when I trigger crs; I just want to grab the selected country shortcode from within the crs script when the selected country changes. Thanks. |
To be more clear, if I change the code,
to The list of regions does correctly change when the country changes, but the alert doesn't fire. It did fire under the older version from last week. |
Hey @wobblymusic! Hmm... I can't think of anything that would affect that change. But do you need to modify the script at all? Might be better to just add your own JS so it won't get overwritten with future upgrades. e.g. just add some JS in your page like To get the value with jQuery, you can do this: $(".your-selector-here").on("change", function() {
console.log("my value is: ", this.value);
console.log("or using jQuery... ", $(this).val());
}); Hope this helps a bit. |
Hi Ben. The problem is that I want to grab the two letter country abbreviation for my other function, but I want crs to give me the full country name in its selector value. How can I grab the two-letter abbreviation outside of crs.js when it's not $(this).val() ? on edit: I realize I could create my own variable of country names and abbreviations, but that seems wrong somehow. |
Ah, I see... Drat. Yes, you're kind of stuck with hacking it in that case. Maybe the least unobtrusive hack would be to edit it to output an extra <option value="full region name here" data-shortcode="shortcode here">full region name here</option> If you're really stuck, email me what you have and I can see if I can edit it this weekend. ben.keen@gmail.com |
I'm not sure what happened -- probably a caching issue -- but my original hack is working now. I can access the country by using |
Good to hear! Thanks for the follow-up. :) |
N.B. on this issue. I thought I'd implement a React version of the country-region-selector script, so will be moving the data source to a separate location in a different format. See: https://github.com/benkeen/country-region-data That way I'll be able to pull that data source into whatever scripts I need and manipulate it into an appropriate format for packaging. |
That seems like a good idea. It also makes it easier for other projects, such as Zippopotam.us to use the data (although I suppose there might be license issues, since they use the OpenData license). |
Thank you for the great script. One feature that would be very useful is to be able to optionally use state/province 2-letter abbreviations as values in the region selector.
The text was updated successfully, but these errors were encountered: