What the fields of the library read from a Phoenix.HTML.FormField (field={@form[:title]}): the id, the
name, the value and the errors, so a form is written as with the core components or any kit that takes a
field, and a field can replace one of them without rewiring the form.
What the caller gives by hand wins: id, name, value and error passed next to field are kept. The
errors are only shown once the person has used the input (Phoenix.Component.used_input?/1), as the core
components do, so an empty form does not open in red.
The library knows no language, so an error {message, options} is translated by the function the app sets:
# config/config.exs
config :devaction_ui, :translate_error, {MyAppWeb.CoreComponents, :translate_error}With none set, the %{count} style placeholders of the message are filled and the text is used as it is.
Summary
Functions
The first error of the field when the caller gave none, for the components that show one message.
The messages of a field's errors, translated, or [] while the person has not used the input.
Fills the assigns of a component from its field, keeping what the caller gave by hand, and sets
:field_errors ([] without a field). opts
Raises when neither the caller nor a field gave the attributes a component cannot do without.
A value as the text of an input: nil stays nil, a Date or a number becomes its string.
One error of a changeset as text, through the :translate_error of the app when there is one.
Functions
The first error of the field when the caller gave none, for the components that show one message.
@spec errors(Phoenix.HTML.FormField.t() | nil) :: [String.t()]
The messages of a field's errors, translated, or [] while the person has not used the input.
Fills the assigns of a component from its field, keeping what the caller gave by hand, and sets
:field_errors ([] without a field). opts:
value:—:text(the value as text, for an input),:raw(as it is: aDate, a list),:checkbox(fillscheckedfrom a boolean field),:member(fillscheckedwhen the component'svalueis in the field's list, for one box of a group),:radio(fillscheckedwhen the component'svalueis the field's) ornil(leaves the value alone)multiple:— the name ends in[]id_suffix:— appended to the field's id, for the boxes and options of a group ("-sge")
Raises when neither the caller nor a field gave the attributes a component cannot do without.
A value as the text of an input: nil stays nil, a Date or a number becomes its string.
One error of a changeset as text, through the :translate_error of the app when there is one.