Skip to content

Commit

Permalink
Copy-paste "humanize" for default labels
Browse files Browse the repository at this point in the history
  • Loading branch information
angelikatyborska committed Jul 16, 2024
1 parent f6062c6 commit 5cb5deb
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/bitstyles_phoenix/component/form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,18 @@ defmodule BitstylesPhoenix.Component.Form do
"""
end

defp default_label(field), do: PhxForm.humanize(field)
defp default_label(field) when is_atom(field), do: default_label(Atom.to_string(field))

defp default_label(field) when is_binary(field) do
bin =
if String.ends_with?(field, "_id") do
binary_part(field, 0, byte_size(field) - 3)
else
field
end

bin |> String.replace("_", " ") |> :string.titlecase()
end

defp required_label(%{required: value} = assigns)
when value not in [nil, false, "false"] do
Expand Down

0 comments on commit 5cb5deb

Please sign in to comment.