formz/widget
Input widgets, like <input>
or <select>
or <textarea>
in HTML.
A widget is essentially just a function that takes the details of a field,
and any render time information that the form generator might need to pass
to an input. e.g. HTML forms elements often need an id
.
I’ve chosen to make the type of the Args here a specific type, rather than something more generic and that any form generator could make. That’s mostly to simplify this package a bit, but it would be easy to make it custom if people need something more versatile without changing the UX experience much. I just don’t know if that’s necessary. Let me know!
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.
Functions
pub fn args(labelled_by labelled_by: LabelledBy) -> Args
helper function to create an Args with the minimum required fields
pub fn described_by(args: Args, db: DescribedBy) -> Args