Liking cljdoc? Tell your friends :D

malli-forms


add-field-specsclj

(add-field-specs schema)
(add-field-specs schema options)

Walk schema structure, building field specs with entry and exit transforms. Does not meaningfully transform schema except in wrapping the values of optional keys in :maybe

Control flow:

  • on enter:
    1. check if schema is flagged as deferring to a child. If so, walk the child TODO: change this behvavior
    2. check if the schema is a ref schema that should be derefed. If so, call m/-walk on the result of derefing it - this preserves path.
    3. otherwise, use type of schema to add context to options before calling m/-walk on children, including render flag if schema is of a collection, and setting required if at root, or schema is a map and optional=false.
    4. if context is marked as render, and schema is a collection, pass flag on. if schema is not a collection, unset flag for walking children (but somehow preserve flag for exit?)
  • on exit:
    • if schema
Walk schema structure, building field specs with entry and exit transforms.
Does not meaningfully transform schema except in wrapping the values of
optional keys in :maybe

Control flow:
- on enter:
  1. check if schema is flagged as deferring to a child. If so, walk the child
    TODO: change this behvavior
  2. check if the schema is a ref schema that should be derefed. If so, call
    m/-walk on the result of derefing it - this preserves path.
  3. otherwise, use type of schema to add context to `options` before calling
    m/-walk on children, including render flag if schema is of a collection,
    and setting required if at root, or schema is a map and optional=false.
  4. if context is marked as render, and schema is a collection, pass flag on.
    if schema is not a collection, unset flag for walking children (but
    somehow preserve flag for exit?)
- on exit:
  - if schema 
raw docstring

auto-placeholderclj

Transformer that adds placeholder values by schema type

Transformer that adds placeholder values by schema type
raw docstring

collect-field-specsclj

(collect-field-specs schema)
(collect-field-specs schema source)
(collect-field-specs schema source options)
(collect-field-specs schema
                     source
                     errors
                     {:malli-forms/keys [add-placeholder-inputs
                                         placeholder-target selected-leaves]
                      :as options})

Given a schema, a value, optional errors, and options, encode the value according to the schema, then value the transformed value, turning it into a ::field-spec AST

Given a schema, a value, optional errors, and options, encode the value
according to the schema, then value the transformed value, turning it into a
::field-spec AST
raw docstring

complete-field-speccljmultimethod

(complete-field-spec schema naive-field-spec child-specs)

Complete or override a field spec for a particular schema. Basic field spec as produced by [[extract-field-spec]] will be provided, as well as specs already generated for children. Keyed on schema type. Default action is to return the naive spec; only necessary to override when child specs inform parent spec in some way, such as with or, and, etc.

Complete or override a field spec for a particular schema. Basic field spec
as produced by [[extract-field-spec]] will be provided, as well as specs
already generated for children. Keyed on schema type.
Default action is to return the naive spec; only necessary to override when
child specs inform parent spec in some way, such as with `or`, `and`, etc.
raw docstring

ensure-map-keysclj

Transformer that ensures that required and optional keys are present in maps by adding nil values when missing.

Transformer that ensures that required and optional keys are present in maps
by adding nil values when missing.
raw docstring

field-spec-properties-keysclj

The keys of a field spec, as they will appear when embedded in the properties of a schema

The keys of a field spec, as they will appear when embedded in the
properties of a schema
raw docstring

field-spec-schemaclj

Schema for a field spec

Schema for a field spec
raw docstring

form-nsclj

Namespace of keys that control behavior on field generation for schemas

Namespace of keys that control behavior on field generation for schemas
raw docstring

handle-submitclj

(handle-submit schema raw-data)
(handle-submit schema raw-data options)

Provide original schema and data as returned by ring-nested-params directly; that is, a map containing the desired value to match against schema under base-data-key. Updates options based on form data, unless ::ignore-form-options is set. Returns a map containing :value, the desired parsed value, :schema, the provided schema, and :form, a delay that, when realized, re-renders the form with the new value and any parse errors encountered. In the scenario that parse errors are encountered, they will be included under :errors.

Provide original schema and data as returned by ring-nested-params directly;
that is, a map containing the desired value to match against `schema` under
base-data-key.
Updates options based on form data, unless ::ignore-form-options is set.
Returns a map containing :value, the desired parsed value, :schema, the
provided schema, and :form, a delay that, when realized, re-renders the form
with the new value and any parse errors encountered. In the scenario that
parse errors are encountered, they will be included under :errors.
raw docstring

parseclj

(parse schema data)
(parse schema data {:malli-forms/keys [validate] :as options})

Simple parse using schema against data. Throws on failure. data should be as returned by ring's nested-params middleware, but should NOT be wrapped in the containing map - that is, the data should match the schema.

Simple parse using schema against data. Throws on failure.
data should be as returned by ring's nested-params middleware, but should NOT
be wrapped in the containing map - that is, the data should match the schema.
raw docstring

parse-failed?clj

(parse-failed? x)

Is x an instance of ParseFailure

Is x an instance of ParseFailure
raw docstring

parse-stackclj

Transformer stack for parsing input data

Transformer stack for parsing input data
raw docstring

parseableclj

Schema types that are subject to m/parse and m/unparse

Schema types that are subject to m/parse and m/unparse
raw docstring

registryclj

malli registry for this project

malli registry for this project
raw docstring

remove-optional-nilsclj

Transformer that removes keys with nil values from maps when those values are optional.

Transformer that removes keys with nil values from maps when those values are
optional.
raw docstring

render-formclj

(render-form schema)
(render-form schema source)
(render-form schema source options)
(render-form schema source errors options)

Renders a form based on a schema. Accepts various optional arguments:

  • source: initial data to seed form with. default: nil
  • options: malli options map. see options-schema for custom keys. default: {}
  • errors: seq of errors produced by m/explain

Rendering a form consists of the following steps:

  1. Provided schema is wrapped in a map, under the key base-data-key. This allows for consistent handling of schemas that aren't maps, as well as allowing for storing other data in the form, such as an anti-forgery token, or signals to this library to help with adding placeholder values.
  2. Wrapped schema is run through add-field-specs, which walks the entire schema, adding path information and calculating various attributes, such as whether or not the given item should render as a field, input type, etc., based on the schema and sometimes its children.
  3. Source data is wrapped in a map under base-data-key (TODO TODO), and transformed according to the prepared schema, ensuring that required map keys are present, adding default values, and adding placeholders based on the provided options; i.e., either in all possible cases, or to a particular field.
  4. The transformed data is walked, using the path to each location in the data to locate a relevant field spec, adding any errors, and outputting nil, the field spec, or a collection field spec with the original value under the key :children; at this point, the output is an AST of the type defined in the local registry as ::field-spec.
  5. The AST is transformed by calling the function under ::render in the options (default: malli-forms.render.table/render) with each node. A good option for this function is a multimethod dispatching on :type; it should return something representing the HTML-encoded form, be it hiccup, or a String directly; depends on what your rendering pipeline looks like.
Renders a form based on a schema. Accepts various optional arguments:
  - source: initial data to seed form with. default: nil
  - options: malli options map. see options-schema for custom keys. default: {}
  - errors: seq of errors produced by m/explain

Rendering a form consists of the following steps:
  1. Provided schema is wrapped in a map, under the key base-data-key. This
    allows for consistent handling of schemas that aren't maps, as well as
    allowing for storing other data in the form, such as an anti-forgery
    token, or signals to this library to help with adding placeholder values.
  2. Wrapped schema is run through add-field-specs, which walks the entire
    schema, adding path information and calculating various attributes, such
    as whether or not the given item should render as a field, input type,
    etc., based on the schema and sometimes its children.
  3. Source data is wrapped in a map under base-data-key (TODO TODO), and
    transformed according to the prepared schema, ensuring that required map
    keys are present, adding default values, and adding placeholders based on
    the provided options; i.e., either in all possible cases, or to a
    particular field.
  4. The transformed data is walked, using the path to each location in the
    data to locate a relevant field spec, adding any errors, and outputting
    nil, the field spec, or a collection field spec with the original value
    under the key :children; at this point, the output is an AST of the type
    defined in the local registry as ::field-spec.
  5. The AST is transformed by calling the function under ::render in the
    options (default: malli-forms.render.table/render) with each node. A good
    option for this function is a multimethod dispatching on :type; it should
    return something representing the HTML-encoded form, be it hiccup, or a
    String directly; depends on what your rendering pipeline looks like.
raw docstring

render-specsclj

(render-specs source)
(render-specs source options)

Given a value as produced by collect-field-specs and options, renders fields defined by AST into markup

Given a value as produced by collect-field-specs and options, renders fields
defined by AST into markup
raw docstring

schema-indexclj

(schema-index schema)

Provide a schema; receive a function that, when called with a value path (as in util/pathwalk), returns the subschema associated with that path

Provide a schema; receive a function that, when called with a value path (as
in util/pathwalk), returns the subschema associated with that path
raw docstring

schema-type->input-typeclj

Simple mapping from schema type to HTML form input type

Simple mapping from schema type to HTML form input type
raw docstring

schema-type-by-input-typeclj

Map of input type keywords to the schema types that they correspond with

Map of input type keywords to the schema types that they correspond with
raw docstring

unnest-seq-transformerclj

Transformer that handles the way data in sequential forms (including sets) will be returned by ring's nested-params middleware, namely:

x[0][a]=1&x[0][b]=2
;=>
{:x {:0 {:a "1", :b "2"}}}

In a nutshell: when this transformer encounters a map where a flat collection is expected, it returns the values of the map. Further coercion should be performed by other transformers, like malli.transformer/collection-transformer

Transformer that handles the way data in sequential forms (including sets)
will be returned by ring's nested-params middleware, namely:
```
x[0][a]=1&x[0][b]=2
;=>
{:x {:0 {:a "1", :b "2"}}}
```
In a nutshell: when this transformer encounters a map where a flat collection
is expected, it returns the values of the map. Further coercion should be
performed by other transformers, like malli.transformer/collection-transformer
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close