From c376974e08e4652b4b07a098f33593be61da09c2 Mon Sep 17 00:00:00 2001 From: Ryan Winchester Date: Fri, 19 Sep 2025 15:18:28 -0300 Subject: [PATCH] allow datetime as form option values --- lib/phoenix_html/form.ex | 3 ++- test/phoenix_html/form_test.exs | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/phoenix_html/form.ex b/lib/phoenix_html/form.ex index b95f1e9..de5f807 100644 --- a/lib/phoenix_html/form.ex +++ b/lib/phoenix_html/form.ex @@ -391,7 +391,8 @@ defmodule Phoenix.HTML.Form do end defp option(group_label, group_values, extra, value) - when is_list(group_values) or is_map(group_values) do + when is_list(group_values) or + (is_map(group_values) and not is_map_key(group_values, :__struct__)) do section_options = escaped_options_for_select(group_values, value, extra) option_tag("optgroup", [label: group_label], {:safe, section_options}) end diff --git a/test/phoenix_html/form_test.exs b/test/phoenix_html/form_test.exs index 87e7416..6c482e0 100644 --- a/test/phoenix_html/form_test.exs +++ b/test/phoenix_html/form_test.exs @@ -293,6 +293,19 @@ defmodule Phoenix.HTML.FormTest do ~s() <> ~s(
) <> ~s() + + assert options_for_select( + [ + {"Open", ~U[2025-01-01 06:30:00.000000Z]}, + {"Close", ~U[2025-01-01 18:30:00.000000Z]} + ], + [ + ~U[2025-01-01 06:30:00.000000Z] + ] + ) + |> safe_to_string() == + ~s() <> + ~s() end test "with custom option tag" do