country-regions / country-region-selector

Dynamic country and region dropdowns for your forms.
http://country-regions.github.io/country-region-selector/
MIT License
252 stars 115 forks source link

data-default-value not set for region if only 1 country #75

Open patrick-levesque opened 5 years ago

patrick-levesque commented 5 years ago

Hi! I'm trying to use this library with only 1 country (US to start with but will add other later) and when I try to set data-default-value for region with previous form value or default to 'California', region dropdown always shows 1st value 'Alabama'. Works well if I have 2 countries or more (ex. US and Canada).

Tried a custom build with grunt customBuild --countries="United States" or using the data-whitelist="US" with all countries.

Here's the code:

<select id="country" name="country" class="form-control input-fields crs-country" data-whitelist="US" data-region-id="province" data-default-value="United States" data-show-default-option="false"></select>

<select id="province" name="province" class="form-control input-fields" data-default-value="California" data-show-default-option="false"></select>

Thanks!

patrick-levesque commented 5 years ago

Quick workaround is to set data-default-value to the desired country, "hide" the country select (display: none;) and show its value in a dummy input field or <p> tag. But this still requires at least 2 countries in the custom build to work.

Would be nice to only update library custom build with new countries without touching each forms in the code...

benkeen commented 5 years ago

Hey @paralel-github, thanks for the heads up. Bug! I'll patch this in the next release - you shouldn't have to do a workaround for this.

chung1905 commented 4 years ago

Hello @benkeen

I create a pull request to fix this issue, can you please check?

Thank you for the awesome projects.