From 5cb5deb3325525311d1a8aaef07faed32a17fce2 Mon Sep 17 00:00:00 2001 From: Angelika Tyborska Date: Tue, 16 Jul 2024 17:02:46 +0200 Subject: [PATCH] Copy-paste "humanize" for default labels --- lib/bitstyles_phoenix/component/form.ex | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/bitstyles_phoenix/component/form.ex b/lib/bitstyles_phoenix/component/form.ex index 7b542ae..36c6ab9 100644 --- a/lib/bitstyles_phoenix/component/form.ex +++ b/lib/bitstyles_phoenix/component/form.ex @@ -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