react-country-region-selector icon indicating copy to clipboard operation
react-country-region-selector copied to clipboard

how do i get the value of country id from the country dropdown??

Open hamzaahmadse opened this issue 6 years ago • 4 comments

i want to get the country and region ids from the dropdown list ??

hamzaahmadse avatar May 04 '18 09:05 hamzaahmadse

Hi @HamzaAhmad932, there aren't really "IDs" associated with the regions or countries - only whatever value attributes you choose for them (either the full country/region name by default, or the shortcodes if you enter valueType="short" on the CountryDropdown/RegionDropdown components).

benkeen avatar Sep 11 '18 03:09 benkeen

@benkeen , Is there a way to get the 'shortCodes' when the valueType="full"? I need to get the short code "US" when I selected "United States of America".

pg185136 avatar Sep 25 '20 20:09 pg185136

I was hoping for this feature as well, but it doesn't look like it's currently supported. I think the workaround for now would be to do a lookup on CountryRegionData after selecting country and region and pull the codes from there.

benWozak avatar Oct 20 '20 19:10 benWozak

@benkeen , Is there a way to get the 'shortCodes' when the valueType="full"? I need to get the short code "US" when I selected "United States of America".

you can try

import { CountryDropdown, RegionDropdown, CountryRegionData } from 'react-country-region-selector';

in render

<CountryDropdown value={this.state.country} onChange={(val) => this.selectCountry(val)} />

and in onchange function

selectCountry(val) { const country = CountryRegionData.find((countryArray) => countryArray[0] === val)[1]; this.setState({ country: val, short_country: country}); }

aswathykrishna1804 avatar Jun 14 '21 13:06 aswathykrishna1804