Skip to content

Commit

Permalink
fix form_input error in border and added field attr in error component
Browse files Browse the repository at this point in the history
  • Loading branch information
phcurado committed Jan 9, 2025
1 parent 1b49607 commit 310c5a2
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/daisy_ui_components/form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ defmodule DaisyUIComponents.Form do
end

def form_input(assigns) do
assigns = add_default_input_assigns(assigns)

~H"""
<div class="form-control w-full">
<.label :if={@label} for={@id} label={@label} />
Expand All @@ -155,8 +157,23 @@ defmodule DaisyUIComponents.Form do
@doc """
Generates a generic error message.
"""
attr :show, :boolean, default: false
slot :inner_block, required: true
attr :field, Phoenix.HTML.FormField,
doc: "a form field struct retrieved from the form, for example: @form[:email]"

slot :inner_block

def error(%{field: %Phoenix.HTML.FormField{} = field} = assigns) do
errors = if Phoenix.Component.used_input?(field), do: field.errors, else: []

assigns =
assigns
|> assign(:field, nil)
|> assign(:errors, Enum.map(errors, &translate(&1)))

~H"""
<.error :for={msg <- @errors}>{msg}</.error>
"""
end

def error(assigns) do
~H"""
Expand Down

0 comments on commit 310c5a2

Please sign in to comment.