Form fields from a malli map schema.
One schema answers three questions: which HTML validation attributes a
field carries (input-attrs), what is wrong with a submitted form
(validate), and what the field looks like with its errors (field). A
field rendered with a :validate-url posts itself there when it changes,
and the server answers with the field again, so the browser shows the
server's verdict without holding any state. Without JavaScript the form
submits whole and the same validate decides.
Error messages are i18n markers ([:t :validation/required]); a page that
is not rendered through wagoe-i18n resolves them with plain-errors.
Form fields from a malli map schema. One schema answers three questions: which HTML validation attributes a field carries (`input-attrs`), what is wrong with a submitted form (`validate`), and what the field looks like with its errors (`field`). A field rendered with a `:validate-url` posts itself there when it changes, and the server answers with the field again, so the browser shows the server's verdict without holding any state. Without JavaScript the form submits whole and the same `validate` decides. Error messages are i18n markers (`[:t :validation/required]`); a page that is not rendered through wagoe-i18n resolves them with `plain-errors`.
(attrs-by-field schema){field-key attrs} for every field of map schema (see input-attrs).
{field-key attrs} for every field of map `schema` (see `input-attrs`).
(decode schema params)Form params as data for map schema: its fields only, each decoded from
the string the browser sent. A blank field is nil where the schema takes
nil, and left out otherwise.
Form `params` as data for map `schema`: its fields only, each decoded from the string the browser sent. A blank field is nil where the schema takes nil, and left out otherwise.
The messages in English, for a page not rendered through wagoe-i18n. The catalogues in wagoe-i18n carry the same keys.
The messages in English, for a page not rendered through wagoe-i18n. The catalogues in wagoe-i18n carry the same keys.
(errors schema data){field-key [message]} for data against map schema, or nil when it is
valid. Messages are i18n markers.
{field-key [message]} for `data` against map `schema`, or nil when it is
valid. Messages are i18n markers.(field schema field-key {:keys [label value errors validate-url attrs options]})The wrapper of field-key in map schema: label, control carrying the
schema's HTML attributes, and the field's errors, tied to the control for
screen readers. With :validate-url the control posts its form there when
it changes (see live-attrs); the handler answers with this function's
output for the submitted value.
opts: :label, :value, :errors (messages), :validate-url, :attrs (merged over the derived attributes), :options ([value label] pairs, for a select of values the schema cannot list, such as the rows a reference may name).
The wrapper of `field-key` in map `schema`: label, control carrying the schema's HTML attributes, and the field's errors, tied to the control for screen readers. With `:validate-url` the control posts its form there when it changes (see `live-attrs`); the handler answers with this function's output for the submitted value. opts: :label, :value, :errors (messages), :validate-url, :attrs (merged over the derived attributes), :options ([value label] pairs, for a select of values the schema cannot list, such as the rows a reference may name).
(field-key schema s)The key of map schema named s, or nil. A request names the field it
validates; this keeps an arbitrary name from becoming a keyword.
The key of map `schema` named `s`, or nil. A request names the field it validates; this keeps an arbitrary name from becoming a keyword.
(field-keys schema)The keys of map schema a form can show, in schema order: every entry but
a nested map or collection.
The keys of map `schema` a form can show, in schema order: every entry but a nested map or collection.
(form attrs & body)A form carrying the request's CSRF token, so it can be submitted without JavaScript.
A form carrying the request's CSRF token, so it can be submitted without JavaScript.
(input-attrs schema field-key)The HTML validation attributes the schema of field-key in map schema
implies: required, type, minlength/maxlength for a string,
min/max (and step) for a number, pattern for a regex on a text
field. nil for a key the schema does not have.
(input-attrs [:map [:name [:string {:min 2}]]] :name) ;=> {:type "text" :required true :minlength 2}
The HTML validation attributes the schema of `field-key` in map `schema`
implies: `required`, `type`, `minlength`/`maxlength` for a string,
`min`/`max` (and `step`) for a number, `pattern` for a regex on a text
field. nil for a key the schema does not have.
(input-attrs [:map [:name [:string {:min 2}]]] :name)
;=> {:type "text" :required true :minlength 2}(label-text field-key)A field's default label: its key, humanised.
A field's default label: its key, humanised.
(live-attrs url field-key)(live-attrs url field-key extra)htmx attributes that post a field's form to url when the field changes,
naming the field as __field (plus extra string pairs), and swap the
answer over the field's wrapper. hx-push-url and hx-encoding are reset
because a control inherits them from an htmx form; multipart would upload
a chosen file on every check.
htmx attributes that post a field's form to `url` when the field changes, naming the field as `__field` (plus `extra` string pairs), and swap the answer over the field's wrapper. `hx-push-url` and `hx-encoding` are reset because a control inherits them from an htmx form; multipart would upload a chosen file on every check.
(plain msg)msg as an English string: a marker looked up in english, anything else
as it is.
`msg` as an English string: a marker looked up in `english`, anything else as it is.
(plain-errors errors)errors with every message plain.
`errors` with every message `plain`.
(validate schema params)Form params checked against map schema: {:data decoded :errors
{field-key [message]}}, :errors nil when the form is valid.
Form `params` checked against map `schema`: {:data decoded :errors
{field-key [message]}}, :errors nil when the form is valid.(value params field-key)The submitted value of field-key in params, keyed by string (Ring form
params) or keyword. A field sent twice — a checkbox and its hidden
fallback — is its last value.
The submitted value of `field-key` in `params`, keyed by string (Ring form params) or keyword. A field sent twice — a checkbox and its hidden fallback — is its last value.
(with-live-validation input-html field-key url)(with-live-validation input-html field-key url extra)input-html with live-attrs on the controls named field-key.
`input-html` with `live-attrs` on the controls named `field-key`.
(wrapper-id field-key)Id of the element wrapping a field: what a per-field validation swaps.
Id of the element wrapping a field: what a per-field validation swaps.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |