question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Theme addresses doesn't show default country

See original GitHub issue

The default country of the logged in user isn’t selected on page load.

Issue seems to be here: if (countrySelect.dataset.default) { countrySelect.value = countrySelect.dataset.default; }

The value should be a country code for it to work, but countrySelect.dataset.default is a full country name.

For example. If one uses data-default=“BE” (Belgium) in templates/customer/addresses in stead of data-default=“{{ form.country }}” it does work.

Note: I’m using a Dutch theme locale on the slate starter theme.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:7
  • Comments:5

github_iconTop GitHub Comments

3reactions
devolkplcommented, Feb 25, 2020

I found another possible bug. If the country is set to “Russia”, the default value of province is not working. My workaround: in populateZones() replace

return zone.name === zoneSelect.dataset.default;

with

return zone.code === zoneSelect.dataset.default;

It requires to make a change in addresses.liquid file. Replace

<select
name="address[province]"
id="AddressProvince_{{ form.id }}"
data-default="{{ form.province }}">

with

<select
name="address[province]"
id="AddressProvince_{{ form.id }}"
data-default="{{ address.province_code }}">
2reactions
tommypepsicommented, Jul 7, 2021

To add to the previous comment here, data-default is expecting the country code and province code but with the example in the read me they use {{ form.country }} and {{ form.province }} which return the country name and province name which leaves the fields blank. Also had to change them to {{ address.country_code }} and {{ address.province_code }} for the field to show the correct values.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Default country set in the form display settings is not applied
Problem/Motivation If I add a address field to a content type and set a default country, the setting is not applied when viewing...
Read more >
Country not shown | WordPress.org
I have tried this but still no country is shown.. Is this because the country is the same as the shop country location?...
Read more >
Setting a Default Country at Checkout - Cratejoy Support
This article will describe how to set this equal to a new country. If your theme does not have a `components` folder, this...
Read more >
Help: Set default country in Address field | 123FormBuilder
You can establish what default country appears on your form in the Address field. Add/Click on your Address field and in the left...
Read more >
How to Change the Default Address Format — AudioTheme
If you're not using the a country code, the plugin attempts to match the country ... doesn't work for you and you want...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found