2019-09-02 14:29:19 +03:00
|
|
|
defmodule PlausibleWeb.ErrorHelpers do
|
|
|
|
use Phoenix.HTML
|
|
|
|
|
2020-12-15 12:30:45 +03:00
|
|
|
def error_tag(%Phoenix.HTML.Form{} = form, field) do
|
2019-09-02 14:29:19 +03:00
|
|
|
Enum.map(Keyword.get_values(form.errors, field), fn error ->
|
2020-12-15 12:30:45 +03:00
|
|
|
content_tag(:div, elem(error, 0), class: "mt-2 text-sm text-red-600")
|
2019-09-02 14:29:19 +03:00
|
|
|
end)
|
|
|
|
end
|
2020-12-15 12:30:45 +03:00
|
|
|
|
|
|
|
def error_tag(assigns, field) when is_map(assigns) do
|
|
|
|
error = assigns[field]
|
|
|
|
|
|
|
|
if error do
|
|
|
|
content_tag(:div, error, class: "mt-2 text-sm text-red-600")
|
|
|
|
end
|
|
|
|
end
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|