Skip to content

fix(kyc): clear stale country-field error on selection and neutralize the misleading hint#825

Merged
TaprootFreak merged 2 commits into
stagingfrom
fix/kyc-country-field-validation
Jul 12, 2026
Merged

fix(kyc): clear stale country-field error on selection and neutralize the misleading hint#825
TaprootFreak merged 2 commits into
stagingfrom
fix/kyc-country-field-validation

Conversation

@TaprootFreak

Copy link
Copy Markdown
Contributor

Problem

The shared KYC country picker (lib/widgets/form/country_field.dart + lib/widgets/form/dropdown_field.dart, used in 5 places: nationality, registration personal step, address step, tax-residence step, and Settings -> Address) showed three independent, long-standing defects:

  1. Misleading hint (H1). The placeholder text was itself a country name ("Schweiz" / "Switzerland"). Because it is only a hint (initial value is null), it looked like a pre-selected country when in fact nothing was chosen.
  2. English item labels (H2). The list items render country.name, the English API name ("Switzerland", "Italy", ...).
  3. Stale validation error (H3) — the actual blocker. After the user pressed "Next" once (Form.validate()), an empty selection produced an (invisible) error string and a red border. Even after the user then picked a valid country, the red border stayed, because DropdownButtonFormField re-validates on change only when an autovalidateMode is set.

Root cause (per observation)

  • H1: countryHint in the ARB files was literally a country name, so a pure placeholder reads as a selection.
  • H2: items map to country.name (English). Note: country.foreignName is not a German localization — it is the endonym (CH = Schweiz, but IT = Italia, FR = France, US = United States). Swapping in foreignName would be wrong for every non-DE country.
  • H3: DropdownButtonFormField in dropdown_field.dart had no autovalidateMode (default: disabled). The validator returns an empty error string for an empty selection -> red border; without onUserInteraction re-validation, didChange on a later valid pick never clears it.

What this fixes

  • H3: DropdownField now forwards an optional autovalidateMode (default null, so every other DropdownField consumer is unchanged). CountryField opts in with AutovalidateMode.onUserInteraction, so selecting a country clears the stale error immediately.
  • H1: countryHint is neutralized to "Land auswählen" / "Select country".

Deliberately NOT fixed

  • H2 stays as-is. Because foreignName is the endonym, not a German label, it is not a correct display source. Real country i18n is a separate concern and is out of scope here.

Affected surfaces (all 5 usage sites)

nationality, registration personal step, address step, tax-residence step, Settings -> Address.

Tests & goldens

  • New regression group in test/widgets/form/country_field_test.dart pinning H3: an untouched field reports an error once the Form is validated, and picking Switzerland afterwards clears hasError (value symbol == 'CH') without a second Form.validate(). Verified the test fails if the autovalidateMode line is removed.
  • Regenerated only the 7 goldens that render the empty country field (Flutter 3.41.6, byte-identical to CI). Each diff is the same small ~0.27% / 896px region = the hint text only (the tax-step country-error golden also just reflects the changed hint inside the red field). No unexpected image changes.
  • flutter analyze: 0 issues. flutter test test/widgets/form/country_field_test.dart: all pass.

@TaprootFreak

Copy link
Copy Markdown
Contributor Author

Verification summary

Root cause (all pre-existing since #141 — not a regression of recent staging work):

  • The KYC country fields hint was itself a country name ("Schweiz"/"Switzerland"), so an empty field looked pre-selected.
  • The shared DropdownField had no autovalidateMode, so after tapping Next on an empty field the red border persisted even after a valid selection (until the next Form.validate()).

Fix

  • Plumb an optional autovalidateMode through DropdownField and set AutovalidateMode.onUserInteraction on the country field -> selecting a country clears the stale error immediately.
  • Neutralize the misleading hint -> Land auswaehlen / Select country.
  • Deliberately not localizing country item names via foreignName (its an endonym — IT=Italia, FR=France — unsuitable as a German label); proper country-name i18n is a separate follow-up.

Applies to all 5 CountryField usages (nationality, personal/address/tax registration steps, settings->edit address).

Verification (m5me, Flutter 3.41.6, byte-identical to CI):

  • flutter analyze: 0 issues
  • flutter test (full): +2789 all green
  • Golden suite: +139 green; 7 affected baselines regenerated (hint-text region only)
  • New widget tests pin the stale-error-clearing behaviour and the neutral hint string
  • Two independent adversarial reviews: 0 blocking findings

Note (out of scope, pre-existing): dropdown items render English country names even in the DE app — a follow-up for the country-name i18n topic above.

@TaprootFreak TaprootFreak marked this pull request as ready for review July 12, 2026 18:28
@TaprootFreak TaprootFreak merged commit 3c09457 into staging Jul 12, 2026
12 checks passed
@TaprootFreak TaprootFreak deleted the fix/kyc-country-field-validation branch July 12, 2026 21:00
TaprootFreak added a commit that referenced this pull request Jul 12, 2026
… hint (#825) (#832)

## Problem

`staging` Visual Regression is **red**: #825 ("neutralize the misleading
hint") changed the country-field `countryHint` from
"Schweiz"/"Switzerland" to "Land auswählen"/"Select country" and
regenerated the **default** country goldens, but the **state** goldens
added by #828 (nationality) and #829 (registration wizard) — which
render the empty country field with the old hint — were merged around
the same time and were not regenerated for #825's change. On current
staging they still show "Schweiz", so they no longer match the rendered
UI.

## Fix

Regenerated exactly the 11 stale state goldens against current `staging`
(with #825's new hint). No test/lib code changed — only the PNG
baselines:

- `kyc_nationality_page_{submit_loading, submit_failure,
validation_error}`
- `kyc_registration_page_{address_step, tax_step,
forwarding_failed_snackbar, submit_failure_snackbar}`
- `kyc_registration_personal_step_{account_type_open, phone_prefix_open,
validation_error}`
- `kyc_registration_address_step_validation_error`

Each now renders the neutral "Land auswählen" placeholder. The other
state goldens in those files (dropdown-open, country-loading,
country-error) don't show the hint and are unchanged.

## Verification

Regenerated on the CI-identical toolchain (Flutter 3.41.6), two
`--update-goldens` runs byte-identical; `git diff` shows exactly these
11 PNGs and nothing else; `flutter analyze` clean; the four affected
golden test files pass against the new baselines. This restores
`staging` to green.
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