-
Notifications
You must be signed in to change notification settings - Fork 104
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
Support "auto" as a default country with geoIP lookup #6
Comments
Note that this enhancement request was added in response to #5, which was a bug about the failure that results if you attempt to use this feature (which the documentation at the time claimed was already implemented). The fix to #5 resolved the error, and corrected the documentation, and was thus closed. Adding the feature as part of the fix to #5 was out of scope, but clearly the feature would be helpful and should be supported. |
+1 |
Tried fixing it: <script> var defaultSelect = ''; var countryViaIp = ''; $.ajax({ url: "https://geoip-db.com/jsonp", jsonpCallback: "callback", dataType: "jsonp", success: function( location ) { defaultSelect = location.country_code; countryViaIp = defaultSelect.toLowerCase(); $("#country").countrySelect({ defaultCountry: countryViaIp, preferredCountries: ['ca', 'gb', 'us'], responsiveDropdown: true }); } }); </script> |
@mrmarkfrench Has this been added to the plugin if yes? how do I get the country by ip |
@iamkarsoft No directly, no, but the snippet above demonstrates a way that you can gain access to the functionality external to the plugin. |
The International Telephone Input plugin that this one is based on supports a defaultCountry option of "auto", which prompts it to perform a geoIP lookup on the client browser and select the current country as the default.
This also necessitates the addition of a geoIpLookup parameter, which provides a function to actually perform the lookup. The assumption here is that a geo-location plugin is already installed (or will be installed to supply this feature), and an appropriate function to invoke it is easy to supply.
This requires both supporting this feature in the first place, and also providing enough information in the documentation to allow users to supply their own lookup function.
The text was updated successfully, but these errors were encountered: