Skip to content

Commit

Permalink
normalize date values
Browse files Browse the repository at this point in the history
  • Loading branch information
woylie committed Dec 10, 2023
1 parent 0a6bffa commit 94bfac5
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/doggo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ defmodule Doggo do
name={@name}
id={@id}
type={@type}
value={Phoenix.HTML.Form.normalize_value(@type, @value)}
value={normalize_value(@type, @value)}
aria-describedby={input_aria_describedby(@id, @errors, @description)}
{@validations}
{@rest}
Expand All @@ -1214,6 +1214,19 @@ defmodule Doggo do
"""
end

defp normalize_value("date", %struct{} = value)
when struct in [Date, NaiveDateTime, DateTime] do
<<date::10-binary, _::binary>> = struct.to_string(value)
{:safe, date}
end

defp normalize_value("date", <<date::10-binary, _::binary>>) do
{:safe, date}
end

defp normalize_value("date", _), do: ""
defp normalize_value(type, value), do: Form.normalize_value(type, value)

defp input_aria_describedby(_, [], []), do: nil
defp input_aria_describedby(id, _, []), do: field_errors_id(id)
defp input_aria_describedby(id, [], _), do: field_description_id(id)
Expand Down

0 comments on commit 94bfac5

Please sign in to comment.