Skip to content

Commit

Permalink
Disable state field for countries without states
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rainerdema committed Nov 7, 2023
1 parent a8ee597 commit 6b220de
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 11 additions & 6 deletions admin/app/components/solidus_admin/ui/forms/address/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}
}

0 comments on commit 6b220de

Please sign in to comment.