View Source Cldr.HTML.Currency (Cldr HTML v1.6.0)
Implements an HTML Form select specifically localised currency display.
Summary
Functions
Generate a list of options for a currency list
that can be used with Phoenix.HTML.Form.options_for_select/2
or
to create a <datalist>.
Generate an HTML select tag for a currency list
that can be used with a Phoenix.HTML.Form.t
.
Types
@type select_options() :: [ currencies: [atom() | binary(), ...], locale: Cldr.Locale.locale_name() | Cldr.LanguageTag.t(), collator: function(), mapper: (Cldr.Currency.t() -> String.t()), backend: module(), selected: atom() | binary() ]
Functions
@spec currency_options(select_options()) :: [tuple()] | {:error, {Cldr.UnknownCurrencyError, binary()}} | {:error, {Cldr.UnknownLocaleError, binary()}}
Generate a list of options for a currency list
that can be used with Phoenix.HTML.Form.options_for_select/2
or
to create a <datalist>.
Arguments
- A
Keyword.t/0
list of options.
Options
See Cldr.HTML.Currency.select/3
for options.
@spec select( form :: Phoenix.HTML.Form.t(), field :: Phoenix.HTML.Form.field(), select_options() ) :: Phoenix.HTML.safe() | {:error, {Cldr.UnknownCurrencyError, binary()}} | {:error, {Cldr.UnknownLocaleError, binary()}}
Generate an HTML select tag for a currency list
that can be used with a Phoenix.HTML.Form.t
.
Arguments
A
Phoenix.HTML.Form.t/0
formA
Phoenix.HTML.Form.field/0
fieldA
Keyword.t/0
list of options
Options
For select options see Phoenix.HTML.Form.options_for_select/2
:currencies
defines the list of currencies to be displayed in the theselect
tag. The list defaults to the currencies returned byMoney.known_tender_currencies/0
if the package ex_money is installed otherwise it is the list returned byCldr.known_currencies/0
:locale
defines the locale to be used to localise the description of the currencies. The default is the locale returned byCldr.get_locale/1
:backend
is any backend module. The default isCldr.default_backend!/0
:collator
is a function used to sort the currencies in the selection list. It is passed a list of maps where each map represents at:Cldr.Currency
. 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.:mapper
is a function that creates the text to be displayed in the select tag for each currency. It is passed the currency definitiont:Cldr.Currency
as returned byCldr.Currency.currency_for_code/2
. The default function is&({&1.code <> " - " <> &1.name, &1.code})
:selected
identifies the currency that is to be selected by default in theselect
tag. The default isnil
. This is passed unmodified to the form generator.:prompt
is a prompt displayed at the top of the select box. This is passed unmodified to the form generator.
Examples
=> Cldr.HTML.Currency.select(:my_form, :currency, selected: :USD)
=> Cldr.HTML.Currency.select(:my_form, :currency, currencies: ["USD", "EUR", :JPY], mapper: &({&1.name, &1.code}))