Skip to content

Commit 6b220de

Browse files
committed
Disable state field for countries without states
Modify the address form logic to accommodate countries without associated states. The state select field is now automatically disabled when a country with no states is selected.
1 parent a8ee597 commit 6b220de

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

admin/app/components/solidus_admin/orders/show/component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def format_address(address)
2121
address.address2,
2222
address.city,
2323
address.zipcode,
24-
address.state.name,
24+
address.state&.name,
2525
tag.br,
2626
address.country.name,
2727
tag.br,

admin/app/components/solidus_admin/ui/forms/address/component.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ export default class extends Controller {
1818

1919
stateSelect.innerHTML = ""
2020

21-
data.forEach(state => {
22-
const option = document.createElement("option")
21+
if (data.length === 0) {
22+
stateSelect.disabled = true
23+
} else {
24+
stateSelect.disabled = false
2325

24-
option.value = state.id
25-
option.innerText = state.name
26-
stateSelect.appendChild(option)
27-
})
26+
data.forEach((state) => {
27+
const option = document.createElement("option")
28+
option.value = state.id
29+
option.innerText = state.name
30+
stateSelect.appendChild(option)
31+
})
32+
}
2833
}
2934
}

0 commit comments

Comments
 (0)