Generates HTML <select> tags and option lists for localized currency display.
Currencies are displayed with their currency code and localized name. The list of currencies, sort order, and display format are all configurable.
Summary
Functions
Generates 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>.
Generates 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: Localize.locale() | Localize.LanguageTag.t(), collator: function(), mapper: (Localize.Currency.t() -> String.t()), selected: atom() | binary() ]
Functions
@spec currency_options(select_options()) :: [tuple()] | {:error, {module(), binary()}}
Generates 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
optionsis aKeyword.t/0list of options.
Options
See Localize.HTML.Currency.select/3 for options.
Returns
A list of
{display_name, currency_code}tuples, or{:error, {module(), binary()}}if validation fails.
@spec select( form :: Phoenix.HTML.Form.t(), field :: Phoenix.HTML.Form.field(), select_options() ) :: Phoenix.HTML.safe() | {:error, {module(), binary()}}
Generates an HTML select tag for a currency list that can be used with a Phoenix.HTML.Form.t.
Arguments
formis aPhoenix.HTML.Form.t/0form.fieldis aPhoenix.HTML.Form.field/0field.optionsis aKeyword.t/0list of options.
Options
:currenciesdefines the list of currencies to be displayed in the select tag. The default isLocalize.Currency.known_currency_codes/0.:localedefines the locale to be used to localise the description of the currencies. The default is the locale returned byLocalize.get_locale/0.:collatoris a function used to sort the currencies in the selection list. The default collator sorts by name.:mapperis a function that creates the text to be displayed in the select tag for each currency. The default function is&({&1.code <> " - " <> &1.name, &1.code}).:selectedidentifies the currency that is to be selected by default in the select tag. The default isnil.:promptis a prompt displayed at the top of the select box.
Returns
A
Phoenix.HTML.safe/0select tag, or{:error, {module(), binary()}}if validation fails.
Examples
iex> Localize.HTML.Currency.select(:my_form, :currency, selected: :USD)