Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions lib/phoenix_html/form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,50 @@ defmodule Phoenix.HTML.Form do
`:second`. All options given to those keys will be forwarded to the
underlying select. See `select/4` for more information.

For example, if you are using Phoenix with Gettext and you want to localize
the list of months, you can pass `:options` to the `:month` key:

# Assuming form contains a User schema
datetime_select form, :born_at, month: [
options: [
{gettext("January"), "1"},
{gettext("February"), "2"},
{gettext("March"), "3"},
{gettext("April"), "4"},
{gettext("May"), "5"},
{gettext("June"), "6"},
{gettext("July"), "7"},
{gettext("August"), "8"},
{gettext("September"), "9"},
{gettext("October"), "10"},
{gettext("November"), "11"},
{gettext("December"), "12"},
]
]

You may even provide your own `localized_datetime_select/3` built on top of
`datetime_select/3`:

defp localized_datetime_select(form, field, opts \\ []) do
opts =
Keyword.put(opts, :month, options: [
{gettext("January"), "1"},
{gettext("February"), "2"},
{gettext("March"), "3"},
{gettext("April"), "4"},
{gettext("May"), "5"},
{gettext("June"), "6"},
{gettext("July"), "7"},
{gettext("August"), "8"},
{gettext("September"), "9"},
{gettext("October"), "10"},
{gettext("November"), "11"},
{gettext("December"), "12"},
])

datetime_select(form, field, opts)
end

## Options

* `:value` - the value used to select a given option.
Expand Down