Skip to content
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

How to get the iso2 code in the name instead of the name field? #85

Open
valtu4a opened this issue Aug 27, 2021 · 2 comments
Open

How to get the iso2 code in the name instead of the name field? #85

valtu4a opened this issue Aug 27, 2021 · 2 comments
Assignees
Labels

Comments

@valtu4a
Copy link

valtu4a commented Aug 27, 2021

In the example from the plugin docs I have found additional attribute data-countrycodeinput="1"
There is also a part of the code which makes a hidden input if it doesn't exist but it doesn't work for me.

// Add the hidden input for the country code
			this.countryCodeInput = $("#"+this.countryInput.attr("id")+"_code");
			if (!this.countryCodeInput) {
				this.countryCodeInput = $('<input type="hidden" id="'+this.countryInput.attr("id")+'_code" name="'+this.countryInput.attr("name")+'_code" value="" />');
				this.countryCodeInput.insertAfter(this.countryInput);
			}
@mrmarkfrench
Copy link
Owner

Interesting. In general, our instructions are that if you want to have the ISO code, you should add the field yourself. I am surprised to see that the code appears to attempt to add it for you.

I'll look into it. In the meantime, just add the field yourself if you want the code.

@mrmarkfrench mrmarkfrench self-assigned this Aug 28, 2021
@boadusamuel
Copy link

@mrmarkfrench I was trying to set the country dynamically with using the country name from the backend but it was not working as expected. I had to change the country name to iso2 before being able to achieve that. I added $.fn[pluginName].getIso2FromCountry = function(country) { return countries.find(c => c.name === country)?.iso2 || null; } to get the iso2 before passing it as the defaultCountry. Please let me know your thought if there is already a solution otherwise I make a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants