View Source Cldr.HTML.Territory (Cldr HTML v1.6.0)
Implements an HTML Form select specifically localised territory display.
Summary
Types
Territory type passed to a collator for ordering in the select box.
Functions
Generate an HTML select tag for a territory list
that can be used with a Phoenix.HTML.Form.t.
Generate a list of options for a territory list
that can be used with Phoenix.HTML.Form.options_for_select/2 or
to create a <datalist>.
Types
@type select_options() :: [ territories: [atom() | binary(), ...], locale: Cldr.Locale.locale_name() | Cldr.LanguageTag.t(), collator: function(), mapper: (Cldr.Locale.territory_code() -> String.t()), backend: module(), selected: atom() | binary() ]
@type territory() :: %{ territory: Cldr.Locale.territory_code(), name: String.t(), flag: String.t() }
Territory type passed to a collator for ordering in the select box.
The default collator orders by :name using Elixir standard
comparison which is by codepoint and is therefore not Unicode
aware.
Functions
@spec select( form :: Phoenix.HTML.Form.t(), field :: Phoenix.HTML.Form.field(), select_options() ) :: Phoenix.HTML.safe() | {:error, {Cldr.UnknownTerritoryError, binary()}} | {:error, {Cldr.UnknownLocaleError, binary()}}
Generate an HTML select tag for a territory list
that can be used with a Phoenix.HTML.Form.t.
Arguments
A
Phoenix.HTML.Form.t/0formA
Phoenix.HTML.Form.field/0fieldA
Keyword.t/0list of options
Options
For select options see Phoenix.HTML.Form.options_for_select/2
:territoriesdefines the list of territories to be displayed in the theselecttag. The list defaults to the territories returned byCldr.Territory.country_codes/0.:styleis the format of the territory name to be used. The options are:standard(the default),:shortand:variant. Not all territories have:shortor:variantnames in which case:standardis used for those territories.:localedefines the locale to be used to localise the description of the territories. The default is the locale returned byCldr.get_locale/1:backendis any backend module. The default isCldr.default_backend!/0:collatoris a function used to sort the territories in the selection list. It is passed a list of maps where each map represents a territory and has the keys:territory,:nameand:flag. Seet:territory. The default collator sorts byname_1 < name_2. As a result, default collation sorts by code point which will not return expected results for scripts other than Latin.:mapperis a function that creates the text to be displayed in the select tag for each territory. It is passed the territory definition as at:territorymap containing the keys:territory_code,:nameand:flag. The default function is&({&1.flag <> " " <> &1.name, &1.territory_code}):selectedidentifies the territory that is to be selected by default in theselecttag. The default isnil. This is passed unmodified to the form generator.:promptis a prompt displayed at the top of the select box. This is passed unmodified to the form generator.
Examples
Cldr.HTML.Territory.select(:my_form, :territory, selected: :AU)
Cldr.HTML.Territory.select(:my_form, :territory, selected: :AU, locale: "ar")
Cldr.HTML.Territory.select(:my_form, :territory, territories: [:US, :AU, :JP],
mapper: &({&1.name, &1.territory_code}))
@spec territory_options(select_options()) :: [tuple()] | {:error, {Cldr.UnknownTerritoryError, binary()}} | {:error, {Cldr.UnknownLocaleError, binary()}}
Generate a list of options for a territory list
that can be used with Phoenix.HTML.Form.options_for_select/2 or
to create a <datalist>.
Arguments
- A
Keyword.t/0list of options.
Options
See Cldr.HTML.Territory.select/3 for options.