formz/widget
The goal of a “widget” in formz
is to produce an HTML input like
<input>
, <select>
, or <textarea>
. In a Definition
,
a widget can be any Gleam type, and it’s up to the form generator being
used to know the exact type you need.
That said, in the bundled form generators a widget is a function that takes the details of a field and some render time arguments that the form generator needs to construct an input. This module is for those form generators, and it’s use is optional if you have different needs.
Types
pub type Args {
Args(
id: String,
labelled_by: LabelledBy,
described_by: DescribedBy,
)
}
Constructors
-
Args( id: String, labelled_by: LabelledBy, described_by: DescribedBy, )
Arguments
-
id
The id of the input element.
-
labelled_by
Details of how the input is labelled. Some sort of label is required for accessibility.
-
described_by
Details of how the input is described. This is optional, but can be useful for accessibility.
-
pub type DescribedBy {
DescribedByElementsWithIds(ids: List(String))
DescribedByNone
}
Constructors
-
DescribedByElementsWithIds(ids: List(String))
The input is described by elements with the specified ids. This is useful for additional instructions or error messages.
-
DescribedByNone
pub type LabelledBy {
LabelledByLabelFor
LabelledByFieldValue
LabelledByElementsWithIds(ids: List(String))
}
Constructors
-
LabelledByLabelFor
The input is labelled by a
<label>
element with afor
attribute pointing to this input’s id. This has the best accessibility support and should be preferred when possible. -
LabelledByFieldValue
The input should be labelled using the
Field
’slabel
field. -
LabelledByElementsWithIds(ids: List(String))
The input is labelled by elements with the specified ids.