Cldr.HTML.Locale.select

You're seeing just the function select, go back to Cldr.HTML.Locale module for more information.
Link to this function

select(form, field, options \\ [])

View Source

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 locale list that can be used with a Phoenix.HTML.Form.t.

Arguments

  • A Phoenix.HTML.Form.t() form

  • A Phoenix.HTML.Form.field() field

  • A Keyword.t() list of options

Options

For select options see Phoenix.HTML.Form.select/4

  • :locales defines the list of locales to be displayed in the the select tag. The list defaults to Cldr.known_locale_names/1. If :backend is specified then the list of locales known to that backend is returned. If no :backend is specified the locales known to Cldr.default_backend!/0 is returned.

  • :locale defines the locale to be used to localise the description of the list of locales. The default is the locale returned by Cldr.get_locale/1 If set to :identity then each locale in the :locales list will be rendered in its own locale.

  • :backend is any backend module. The default is Cldr.default_backend!/0

  • :collator is a function used to sort the locales in the selection list. It is passed a list of maps where each map represents a locale. The default collator sorts by locale_1.display_name < locale_2.display_name. 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 locale. It is passed a map with three fields: :display_name, :locale and :language_tag. The default mapper is &{&1.display_name, &1.locale}. See t:locale.

  • :selected identifies the locale that is to be selected by default in the select tag. The default is nil. This is passed to Phoenix.HTML.Form.select/4

  • :prompt is a prompt displayed at the top of the select box. This is passed unmodified to Phoenix.HTML.Form.select/4

Notes

If :locale is set to :identity then each locale in :locales will be used to render its own display name. In this case each locale in :locales must also be configured in the :backend or an error will be returned.

Examples

 Cldr.HTML.Currency.select(:my_form, :locale_list, selected: "en")

 Cldr.HTML.Currency.select(:my_form, :locale_list,
   locales: ["zh-Hant", "ar", "fr"],
   mapper: &({&1.display_name, &1.locale}))