mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-09-09 07:08:20 +00:00
feat: implement pre-selection for nationality and nation fields by repurposing the placeholder field to store default values
This commit is contained in:
@@ -104,6 +104,12 @@ export interface FormFieldConfig {
|
||||
label: Bilingual;
|
||||
type: FormFieldType;
|
||||
required?: boolean;
|
||||
/**
|
||||
* Hint text — except on NATIONALITY/NATION fields, where the builder puts
|
||||
* the pre-selected answer here (`en`, as the English demonym or country
|
||||
* name) and the wizard seeds it into the draft. The server stores it
|
||||
* unchanged either way, so this stays frontend-only.
|
||||
*/
|
||||
placeholder?: Bilingual;
|
||||
helpText?: Bilingual;
|
||||
options?: { value: string; label: Bilingual }[];
|
||||
|
||||
@@ -56,6 +56,28 @@ export function getNationalityCode(name: string | null | undefined, lang: Countr
|
||||
return demonymCode || getCountryCode(name, lang);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stored form of a NATIONALITY/NATION answer — the English demonym or country
|
||||
* name, the way the profile's Address tab and seafarer registration store it,
|
||||
* so a certificate prints the word rather than "ET" — resolved back to the
|
||||
* alpha-2 code the picker works in. Both lookups run either way so an answer
|
||||
* saved in the other form (or as a bare code) still resolves.
|
||||
*/
|
||||
export function countryValueToCode(stored: unknown, demonym: boolean): string | null {
|
||||
const raw = typeof stored === 'string' ? stored.trim() : '';
|
||||
if (!raw) return null;
|
||||
const code = demonym
|
||||
? getNationalityCode(raw) ?? getCountryCode(raw)
|
||||
: getCountryCode(raw) ?? getNationalityCode(raw);
|
||||
return code ?? raw;
|
||||
}
|
||||
|
||||
/** The reverse: English-pinned deliberately, so the stored answer never depends on the UI language. */
|
||||
export function countryCodeToValue(code: string | null, demonym: boolean): string | null {
|
||||
if (!code) return null;
|
||||
return (demonym ? getNationalityName(code) : getCountryName(code)) || code;
|
||||
}
|
||||
|
||||
export function CountryFlag({ code }: { code: string }) {
|
||||
const Flag = Flags[code as keyof typeof Flags];
|
||||
return Flag ? <Flag style={{ width: 22, borderRadius: 2, display: 'block' }} /> : null;
|
||||
|
||||
Reference in New Issue
Block a user