Cldr.HTML.Currency (Cldr HTML v0.4.0) View Source
Implements Phoenix.HTML.Form.select/4 specifically for
localised currency display.
Link to this section Summary
Functions
Generate an HTML select tag for a currency list
that can be used with a Phoenix.HTML.Form.t.
Link to this section Types
Specs
select_options() :: [ currencies: [atom() | binary(), ...], locale: Cldr.Locale.locale_name() | Cldr.LanguageTag.t(), mapper: function(), backend: module(), selected: atom() | binary() ]
Link to this section Functions
Specs
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()formA
Phoenix.HTML.Form.field()fieldA
Keyword.t()list of options
Options
For select options see Phoenix.HTML.Form.select/4
:currenciesdefines the list of currencies to be displayed in the theselecttag. The list defaults to the currencies returned byMoney.known_tender_currencies/0if the package ex_money is installed otherwise it is the list returned byCldr.known_currencies/0:localedefines the locale to be used to localise the description of the currencies. The default is the locale returned byCldr.get_locale/1:backendis any backend module. The default isCldr.default_backend!/0:mapperis a function that creates the text to be displayed in the select tag for each currency. It is passed the currency definitionCldr.Currency.tas returned byCldr.Currency.currency_for_code/2. The default function is&({&1.code <> " - " <> &1.name, &1.code}):selectedidentifies the currency that is to be selected by default in theselecttag. The default isnil. This is passed unmodified toPhoenix.HTML.Form.select/4:promptis a prompt displayed at the top of the select box. This is passed unmodified toPhoenix.HTML.Form.select/4
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}))