ditto-0.1.2.0: ditto is a type-safe HTML form generation and validation library

Ditto.Core

Description

This module defines the Form type, its instances, core manipulation functions, and a bunch of helper utilities.

Synopsis

Proved

data Proved a Source #

Proved records a value, the location that value came from, and something that was proved about the value.

Constructors

 Proved Fieldspos :: FormRange unProved :: a
Instances

Form

newtype Form m input error view a Source #

a Form contains a View combined with a validation function which will attempt to extract a value from submitted form data.

It is highly parameterized, allowing it work in a wide variety of different configurations. You will likely want to make a type alias that is specific to your application to make type signatures more manageable.

m
A monad which can be used by the validator
input
A framework specific type for representing the raw key/value pairs from the form data
error
A application specific type for error messages
view
The type of data being generated for the view (HSP, Blaze Html, Heist, etc)
proof
A type which names what has been proved about the pure value. () means nothing has been proved.
a
Value pure by form when it is successfully decoded, validated, etc.

This type is very similar to the Form type from digestive-functors <= 0.2. If proof is (), then Form is an applicative functor and can be used almost exactly like digestive-functors <= 0.2.

Constructors

 Form FieldsunForm :: FormState m input (View error view, m (Result error (Proved a)))
Instances
 Functor m => Functor (Form m input error view) Source # Instance detailsDefined in Ditto.Core Methodsfmap :: (a -> b) -> Form m input error view a -> Form m input error view b #(<\$) :: a -> Form m input error view b -> Form m input error view a # (Functor m, Monoid view, Monad m, x ~ ()) => Applicative (Form m input error view) Source # Instance detailsDefined in Ditto.Core Methodspure :: a -> Form m input error view a #(<*>) :: Form m input error view (a -> b) -> Form m input error view a -> Form m input error view b #liftA2 :: (a -> b -> c) -> Form m input error view a -> Form m input error view b -> Form m input error view c #(*>) :: Form m input error view a -> Form m input error view b -> Form m input error view b #(<*) :: Form m input error view a -> Form m input error view b -> Form m input error view a #

bracketState :: Monad m => FormState m input a -> FormState m input a Source #

Ways to evaluate a Form

runForm :: Monad m => Environment m input -> Text -> Form m input error view a -> m (View error view, m (Result error (Proved a))) Source #

Run a form

runForm' :: Monad m => Environment m input -> Text -> Form m input error view a -> m (view, Maybe a) Source #

Run a form

Arguments

 :: Monad m => Text form prefix -> Form m input error view a form to view -> m view

Just evaluate the form to a view. This usually maps to a GET request in the browser.

Arguments

 :: Monad m => Environment m input Input environment -> Text Identifier for the form -> Form m input error view a Form to run -> m (Either view a) Result

Evaluate a form

Returns:

Left view
on failure. The view will have already been applied to the errors.
Right a
on success.

Arguments

 :: Monad m => view View to insert -> Form m input error view () Resulting form

create a Form from some view.

This is typically used to turn markup like <br> into a Form.

(++>) :: (Monad m, Semigroup view) => Form m input error view () -> Form m input error view a -> Form m input error view a infixl 6 Source #

Append a unit form to the left. This is useful for adding labels or error fields.

The Forms on the left and right hand side will share the same FormId. This is useful for elements like <label for="someid">, which need to refer to the id of another element.

(<++) :: (Monad m, Semigroup view) => Form m input error view a -> Form m input error view () -> Form m input error view a infixr 5 Source #

Append a unit form to the right. See ++>.

Arguments

 :: (Monad m, Functor m) => (view -> view') Manipulator -> Form m input error view a Initial form -> Form m input error view' a Resulting form

Change the view of a form using a simple function

This is useful for wrapping a form inside of a <fieldset> or other markup element.

mkOk :: Monad m => FormId -> view -> a -> FormState m input (View error view, m (Result error (Proved a))) Source #

Utility Function: turn a view and pure value into a successful FormState