Tanguv0.35.0
Web & HTTP20 exports
Raw Markdown

/web/app/forms

HTML form binding, type coercion, CSRF token fields (<csrf-field>), and field validation errors (<form-error>).

(use /web/app/forms)

Functions & symbols#

Validation#

constructor
(Validation ok errors) -> Validation

Re-exported Validation result struct from `/validation`.

ParameterTypeOptionalDescription
okBoolrequiredOverall validation success flag
errorsMaprequiredMap of {:field [error-messages...]}
Returns:Any
(let res (Validation true {}))

ValidationErrors#

constructor
(ValidationErrors errors [values]) -> ValidationErrors

Re-exported ValidationErrors struct from `/validation`.

ParameterTypeOptionalDescription
errorsMaprequiredField error arrays keyed by field KeySymbol
valuesMapoptionalSubmitted raw input values
Returns:Any
(ValidationErrors {:email ["Invalid email"]})

add-field-error#

function
(add-field-error target field message)

Attaches a custom error message to `field` on `target` (a Struct, `ValidationErrors`, or `Map`), returning a `ValidationErrors`.

ParameterTypeOptionalDescription
targetAnyrequired—
fieldAnyrequired—
messageAnyrequired—
Returns:Any

coerce-field-value#

function
(coerce-param-value raw-value type-name constraints)

Coerces a raw form field value into `type-name` using the unified parameter coercion engine.

ParameterTypeOptionalDescription
raw-valueAnyrequired—
type-nameAnyrequired—
constraintsAnyrequired—
Returns:Any

extract-inner-type#

function
(extract-inner-type type-str)

Extracts the inner type name from an optional `(Maybe T)` or `(Or T)` type string.

ParameterTypeOptionalDescription
type-strAnyrequired—
Returns:Any

first-error-of#

function
(first-error-of target)

Returns the first validation error message across all fields in `target`, or `()` if none exist.

ParameterTypeOptionalDescription
targetAnyrequired—
Returns:Any

flat-errors-of#

function
(flat-errors-of target)

Projects `target`'s errors into a flat `{:field "first error"}` map suitable for UI components.

ParameterTypeOptionalDescription
targetAnyrequired—
Returns:Any

get-field-error#

function
(get-field-error target field)

Returns the first error message string for `field` on `target`, or `()` if valid.

ParameterTypeOptionalDescription
targetAnyrequired—
fieldAnyrequired—
Returns:Any

get-field-errors#

function
(get-field-errors target field)

Returns the array of error messages for `field` on `target`, or `[]` if valid.

ParameterTypeOptionalDescription
targetAnyrequired—
fieldAnyrequired—
Returns:Any

get-field-value#

function
(get-field-value ...args)

Looks up a field value on a Struct instance, `ValidationErrors`, or `Map`, returning `default-val` when absent.

ParameterTypeOptionalDescription
argsAnyoptional—
Returns:Any

has-field-error?#

function
(has-field-error? ...args)

Returns true if `target` has any validation error (or an error on `field` when `field` is provided).

ParameterTypeOptionalDescription
argsAnyoptional—
Returns:Any

is-file-selected?#

function
(is-file-selected? upload)

Returns true if a multipart file upload map contains a non-empty filename and non-empty content.

ParameterTypeOptionalDescription
uploadAnyrequired—
Returns:Any

is-maybe-type?#

function
(is-maybe-type? type-str)

Returns true if `type-str` is an optional `(Maybe ...)` or `(Or ...)` type.

ParameterTypeOptionalDescription
type-strAnyrequired—
Returns:Any

is-valid?#

function
(is-valid? instance [schema]) -> Bool

Re-exported validation check predicate from `/validation`.

ParameterTypeOptionalDescription
instanceAnyrequiredStruct instance or Map
schemaStruct | MapoptionalOptional target Struct descriptor
Returns:Any
(assert! (validation/is-valid? user))

merge-form-errors#

function
(merge-form-errors ...targets)

Merges two or more `ValidationErrors` (or ` ():` / valid targets) into a single `ValidationErrors`, or returns `()` if all are valid.

ParameterTypeOptionalDescription
targetsAnyoptional—
Returns:Any

read-form#

function
(read-form req struct-type)

Reads and coerces a request's form body into `struct-type` (re-exported from `/web/app`).

ParameterTypeOptionalDescription
reqAnyrequired—
struct-typeAnyrequired—
Returns:Any

respond-form-errors#

function
(respond-form-errors ...args)

Returns a 422 Unprocessable Entity response negotiated for JSON, Stage/HTML (via `render-fn`), or plain text.

ParameterTypeOptionalDescription
argsAnyoptional—
Returns:Any

validate#

function
(validate instance [schema]) -> Validation

Re-exported struct validation function from `/validation`.

ParameterTypeOptionalDescription
instanceAnyrequiredStruct instance or Map to validate
schemaStruct | MapoptionalOptional target Struct descriptor when validating raw Maps
Returns:Any
(let v (validation/validate signup-form))

validate-form#

function
(validate-form ...args)

Validates a form struct instance or parses and validates `req` against `struct-type`, returning a `Validation`.

ParameterTypeOptionalDescription
argsAnyoptional—
Returns:Any

validate-upload#

function
(validate-upload upload ...rest)

Validates a multipart file upload map against `:required`, `:max-bytes`, and `:accept` rules, returning `()` or `ValidationErrors`.

ParameterTypeOptionalDescription
uploadAnyrequired—
restAnyoptional—
Returns:Any