Skip to content

Non-USA address state text box and smarter new-address defaults - #2843

Merged
maebeale merged 6 commits into
mainfrom
maebeale/state-text-box-non-usa
Oct 25, 2026
Merged

maebeale merged 6 commits into
mainfrom
maebeale/state-text-box-non-usa

Conversation

@maebeale

@maebeale maebeale commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

🤖 suggested review level: 3 Read 📖 small view/decorator logic shared by person and org address forms, plus a nested-attributes reject rule

Canadian addresses saved as "CA" (Canada) showed up as California with no way to enter a province — non-USA addresses now get a State text box, and new addresses start from the saved one.

What is the goal of this PR and why is this important?

  • State dropdown is US-only, so international addresses couldn't hold a correct value.
  • People adding a second address had to re-pick country, state, and locality.

How did you approach the change?

  • State text box when the address (or its default country) is outside the USA.
    • Admins get the dropdown by default; ?admin=true gives them the text box on any address (AddressPolicy#enter_any_state?).
  • New address defaults copy the saved address: country, state, locality.
    • An active address wins over a retired one, then the most recently updated. The primary flag is pre-checked on every address added, so it can't pick the current one.
    • No saved address → country from the Settings return address (Setting.default_address_country), else United States.
  • Blank locality → whatever AddressLocality settles from the address (Outside USA, Outside CA, LA City, LA County, Orange County), blank when it can't guess.
  • Country stays optional; the hint still offers blank.
  • Logic on AddressDecorator; one shared addresses/_state_field partial; no JS.

An empty address block has to stay droppable

  • Pre-filling made an untouched "Add address" block look filled to reject_if, so the block was built and the parent save died on "Addresses city can't be blank".
  • reject_if now checks only city, street_address, zip_code (Address.unfilled_attributes?) — the fields someone types. Person and Organization shared one copy of the old proc.
  • Address::DEFAULT_COUNTRY is now the only place "United States" is written; GeographyHelper and AddressTranslation point at it. A spelling that drifts from the option string renders the select blank.

Features seed (optional)

  • Added a features seed (optional)

UI Testing Checklist

  • Person edit, US address → state dropdown
  • Person edit, Canada address → state text box
  • Person with a saved address → Add address copies its country, state, locality
  • Person whose only live address is retired → Add address skips it for the active one
  • Person with no addresses → Add address starts in the return address's country
  • Admin with ?admin=true → text box on a US address
  • Org edit, non-USA address → text box
  • Org edit → Add Address, fill in nothing, Save → saves clean, no new address

Anything else to add?

  • Changing the country doesn't swap the state field until the address is saved and reopened; admins can use ?admin=true in the meantime.

🤖 Generated with Claude Code

maebeale and others added 2 commits October 25, 2026 06:47
Canadian addresses stored "CA" for Canada rendered as California in the
US-only dropdown, with no way to enter a province. Non-USA addresses now get
a text box; admins can force one with admin=true to fix US-looking values.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A second address abroad shouldn't make the person re-pick their country, and
the state field and locality should follow it. Country is required only on
the person/org forms so imports and registration capture keep saving.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@maebeale maebeale changed the title Let non-USA addresses type their state Non-USA address state text box, country defaults, and required country Oct 25, 2026
…address's country

A second address usually shares the first one's country, state, and locality,
and with nothing saved the organization's own country is the better guess than
a hard-coded US. Country stays optional for now.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@maebeale maebeale changed the title Non-USA address state text box, country defaults, and required country Non-USA address state text box and smarter new-address defaults Oct 25, 2026
@maebeale
maebeale marked this pull request as ready for review October 25, 2026 11:05
maebeale and others added 3 commits October 25, 2026 07:14
…e address

Review turned up three things the form got wrong. A blank locality reinvented the
locality rules, so a state no US state answers to ("ON" with no country) was offered
as Outside CA where AddressLocality deliberately declines to guess; delegating to it
also recovers the LA City / LA County / Orange County answers the form was throwing
away. A new address seeded itself from a retired address as readily as a live one,
and the primary flag it preferred is pre-checked on every address added, so it
rarely pointed at the current one — active first, then most recently updated. And
the country hint still told people to pick one after the requirement was reverted.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Pre-filling a new block's country, state and locality from the saved address
made an untouched "Add address" block look filled to the nested-attributes
reject_if, which slices all five of locality, city, state, street_address and
zip_code. The block was built instead of dropped, and the parent save failed on
"Addresses city can't be blank" — an organization form could no longer be saved
after someone opened an address block and changed their mind.

Reject on the three fields a person actually has to type. The other three arrive
pre-filled, so they say nothing about whether anyone touched the block, and an
address holding only those can never pass validation anyway.

Both models carried the same proc, so the list lives on Address with the comment
explaining it. While there, point GeographyHelper and AddressTranslation at
Address::DEFAULT_COUNTRY so the dropdown's spelling of the US is written once —
a value that drifts from the option string renders the select blank.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@maebeale
maebeale merged commit 88f4808 into main Oct 25, 2026
3 checks passed
@maebeale
maebeale deleted the maebeale/state-text-box-non-usa branch October 25, 2026 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant