diff --git a/admin/app/components/solidus_admin/orders/show/component.rb b/admin/app/components/solidus_admin/orders/show/component.rb index eddc4c4ac10..36a672d06a0 100644 --- a/admin/app/components/solidus_admin/orders/show/component.rb +++ b/admin/app/components/solidus_admin/orders/show/component.rb @@ -21,7 +21,7 @@ def format_address(address) address.address2, address.city, address.zipcode, - address.state.name, + address.state&.name, tag.br, address.country.name, tag.br, diff --git a/admin/app/components/solidus_admin/ui/forms/address/component.html.erb b/admin/app/components/solidus_admin/ui/forms/address/component.html.erb index 5a2a18c0691..e4c66ad6057 100644 --- a/admin/app/components/solidus_admin/ui/forms/address/component.html.erb +++ b/admin/app/components/solidus_admin/ui/forms/address/component.html.erb @@ -25,6 +25,7 @@ :state_id, state_options, value: @form.object.try(:state_id), + disabled: @form.object.country&.states&.empty?, "data-#{stimulus_id}-target": "state" ) %> diff --git a/admin/app/components/solidus_admin/ui/forms/address/component.js b/admin/app/components/solidus_admin/ui/forms/address/component.js index acded52e2b9..1b255ee39a4 100644 --- a/admin/app/components/solidus_admin/ui/forms/address/component.js +++ b/admin/app/components/solidus_admin/ui/forms/address/component.js @@ -18,12 +18,17 @@ export default class extends Controller { stateSelect.innerHTML = "" - data.forEach(state => { - const option = document.createElement("option") + if (data.length === 0) { + stateSelect.disabled = true + } else { + stateSelect.disabled = false - option.value = state.id - option.innerText = state.name - stateSelect.appendChild(option) - }) + data.forEach((state) => { + const option = document.createElement("option") + option.value = state.id + option.innerText = state.name + stateSelect.appendChild(option) + }) + } } }