Generates HTML <select> tags and option lists for localized month name display.
Month names are sourced from CLDR calendar data and localized according to the current or specified locale. The display style (wide, abbreviated, narrow), calendar system, and sort order are all configurable.
Summary
Functions
Generates a list of options for a month 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 month name list that can be used with a Phoenix.HTML.Form.t.
Types
@type select_options() :: [ months: [pos_integer(), ...], locale: Localize.locale() | Localize.LanguageTag.t(), calendar: Calendar.calendar(), year: Calendar.year(), style: :wide | :abbreviated | :narrow, collator: function(), mapper: function(), selected: pos_integer() ]
Functions
@spec month_options(select_options()) :: [tuple()]
Generates a list of options for a month 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.Month.select/3 for options.
Returns
- A list of
{month_name, month_number}tuples.
@spec select( form :: Phoenix.HTML.Form.t(), field :: Phoenix.HTML.Form.field(), select_options() ) :: Phoenix.HTML.safe()
Generates an HTML select tag for a month name 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
:monthsdefines the list of month numbers to be displayed. The default is1..12.:calendaris the calendar module from which the month names are derived. The default isCalendar.ISO, which renders Gregorian labels. If the calendar module exportscldr_calendar_type/0, the returned atom selects the CLDR calendar used for the labels (for example,Cldr.Calendar.Hebrewreturns:hebrew). Calendars without that function fall back to Gregorian labels.:yearis the year from which the number of months is derived. The default is the current year.:localedefines the locale used to localise the month names. The default is the locale returned byLocalize.get_locale/0.:styleis the format of the month name. The options are:wide(the default),:abbreviatedand:narrow.:collatoris a function used to sort the months. The default collator preserves month order.:mapperis a function that creates the text to be displayed in the select tag for each month. It receives a tuple{month_name, month_number}. The default is the identity function.:selectedidentifies the month 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.
Examples
iex> Localize.HTML.Month.select(:my_form, :month, selected: 1)