react-country-region-selector
react-country-region-selector copied to clipboard
how do i get the value of country id from the country dropdown??
i want to get the country and region ids from the dropdown list ??
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 , 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".
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.
@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}); }