Use user's locale for native date picker

This commit is contained in:
Alex Lion
2026-08-03 11:22:41 +07:00
parent 73b458e998
commit ff137667ed
3 changed files with 13 additions and 0 deletions

View File

@@ -264,6 +264,7 @@
form={f}
key={:started_at}
name={gettext("Start date and time")}
locale={@current_user.locale}
required="true"
/>
<p class="text-xs text-base-content/60">{gettext("Shown in your local time.")}</p>

View File

@@ -272,6 +272,7 @@ defmodule ClaperWeb.Component.Input do
|> assign_new(:autofocus, fn -> false end)
|> assign_new(:placeholder, fn -> false end)
|> assign_new(:readonly, fn -> false end)
|> assign_new(:locale, fn -> Gettext.get_locale(ClaperWeb.Gettext) end)
|> assign_new(:labelClass, fn -> "text-gray-700" end)
|> assign_new(:fieldClass, fn -> "bg-white" end)
@@ -286,6 +287,7 @@ defmodule ClaperWeb.Component.Input do
readonly: @readonly,
autofocus: @autofocus,
autocomplete: "off",
lang: @locale,
step: 300,
class:
"input h-12 w-full bg-white px-4 read-only:opacity-50 #{if Keyword.has_key?(@form.errors, @key), do: "input-error", else: ""}"

View File

@@ -65,6 +65,16 @@ defmodule ClaperWeb.EventLiveTest do
assert has_element?(new_live, ~s(button[form="event-form"]), "Create event")
end
test "uses the user's locale for the native date picker", %{user: user} do
{:ok, %{locale: "fr"} = user} =
Claper.Accounts.update_user_preferences(user, %{locale: "fr"})
conn = build_conn() |> log_in_user(user)
{:ok, new_live, _html} = live(conn, ~p"/events/new")
assert has_element?(new_live, ~s(#date-picker input[type="datetime-local"][lang="fr"]))
end
test "adds and removes an unsaved facilitator", %{
conn: conn,
presentation_file: presentation_file