Helpers for building custom form controls with the same ids and ARIA
attributes as the field component.
Summary
Functions
Returns the id of the description of the field with the given input id.
Returns the id of the error list of the field with the given input id.
Returns the aria-describedby value of an input: the ids of the error list
and the description, if the field has them, or nil.
Returns the aria-errormessage value of an input: the id of the error list
if there are errors, or nil.
Interpolates the values of an error into its message, without translating it.
Functions
Returns the id of the description of the field with the given input id.
Example
iex> Doggo.Form.field_description_id("pet-name")
"pet-name-description"
Returns the id of the error list of the field with the given input id.
Example
iex> Doggo.Form.field_errors_id("pet-name")
"pet-name-errors"
Returns the aria-describedby value of an input: the ids of the error list
and the description, if the field has them, or nil.
description and errors are lists, such as the entries of a description
slot and the error messages. The id of the error list comes first, as in the
markup of field.
The id of the error list is also the aria-errormessage value (see
input_aria_errormessage/2). It is included here as well, since screen
readers support aria-errormessage inconsistently.
Examples
iex> Doggo.Form.input_aria_describedby("pet-name", [], [])
nil
iex> Doggo.Form.input_aria_describedby("pet-name", [], ["is too short"])
"pet-name-errors"
iex> Doggo.Form.input_aria_describedby("pet-name", ["Your pet's name"], [])
"pet-name-description"
iex> Doggo.Form.input_aria_describedby(
...> "pet-name",
...> ["Your pet's name"],
...> ["is too short"]
...> )
"pet-name-errors pet-name-description"
Returns the aria-errormessage value of an input: the id of the error list
if there are errors, or nil.
Example
iex> Doggo.Form.input_aria_errormessage("pet-name", ["is too short"])
"pet-name-errors"
Interpolates the values of an error into its message, without translating it.
This is the default of the translate_error build option of field.
Example
iex> Doggo.Form.translate_error({"must have %{count} items", [count: 3]})
"must have 3 items"