Module

Formless

Package
purescript-formless-aj
Repository
ajnsit/purescript-formless-independent

Formless is a renderless component to help you build forms in a UI independent way. This module re-exports all public functions and types from the library, and can be used as the single import for most use cases.

import Formless as F

Re-exports from Formless.Class.Initial

#Initial Source

class Initial v  where

A type class that provides initial values for form fields. While superficially similar to Haskell's Default type class, this class is only meant for the purposes of defining initial form values. If you need a default value for a field in your form, you are better off defining it as a Maybe field and providing a default as part of validation.

In general, if you find yourself reaching for this type class without defining your form as a row and generating your form spec from it, then you are probably not doing what you intend.

Members

Instances

Re-exports from Formless.Component

#eval Source

eval :: forall ivfs ifs os vs us fxs fs ivs ixs is m form. RowToList is ixs => RowToList fs fxs => EqRecord ixs is => InputFieldsToFormFields ixs is fs => FormFieldsToInputFields fxs fs is => CountErrors fxs fs => AllTouched fxs fs => SetFormFieldsTouched fxs fs fs => ReplaceFormFieldInputs is fxs fs fs => ModifyAll ifs fxs fs fs => ValidateAll vs fxs fs fs m => FormFieldToMaybeOutput fxs fs os => Newtype (form Record InputField) (Record is) => Newtype (form Record InputFunction) (Record ifs) => Newtype (form Record FormField) (Record fs) => Newtype (form Record OutputField) (Record os) => Newtype (form Record (Validation form m)) (Record vs) => Newtype (form Variant InputField) (Variant ivs) => Newtype (form Variant InputFunction) (Variant ivfs) => Newtype (form Variant U) (Variant us) => Monad m => Query form -> State form m -> m (Either (State form m) (form Record OutputField))

Re-exports from Formless.Data.FormFieldResult

#FormFieldResult Source

data FormFieldResult error output

A data type which represents the possible output states of the field. Use the helpers in Retrieve to easily manipulate this type.

Constructors

Instances

#toMaybe Source

toMaybe :: forall o e. FormFieldResult e o -> Maybe o

#fromEither Source

fromEither :: forall o e. Either e o -> FormFieldResult e o

#_Success Source

_Success :: forall o e. Prism' (FormFieldResult e o) o

#_Error Source

_Error :: forall o e. Prism' (FormFieldResult e o) e

Re-exports from Formless.Query

#validateAll Source

validateAll :: forall form. Query form

Validate all fields in the form, collecting errors

#validate Source

validate :: forall o i e t0 sym us form. IsSymbol sym => Newtype (form Variant U) (Variant us) => Cons sym (U e i o) t0 us => SProxy sym -> Query form

A helper to create the correct Validate query for Formless, given a label

#submit Source

submit :: forall form. Query form

Submit the form, which will trigger a Submitted result if the form validates successfully.

#setValidateAll Source

setValidateAll :: forall is' is form. Newtype (form Record InputField) (Record is') => HMap WrapField (Record is) (Record is') => Record is -> Query form

Provide a record of inputs to overwrite all current inputs without resetting the form (as initialize does), and then validate the entire new set of fields. Similar to calling setValidate on every field in the form.

#setValidate Source

setValidate :: forall o i e t0 sym inputs form. IsSymbol sym => Newtype (form Variant InputFunction) (Variant inputs) => Cons sym (InputFunction e i o) t0 inputs => SProxy sym -> i -> Query form

Set the input value of a form field at the specified label, also triggering validation to run on the field.

#setAll Source

setAll :: forall is' is form. Newtype (form Record InputField) (Record is') => HMap WrapField (Record is) (Record is') => Record is -> Query form

Provide a record of input fields to overwrite all current inputs. Unlike initialize, this does not otherwise reset the form as if it were new. Similar to calling set on every field in the form.

#set Source

set :: forall o i e t0 sym inputs form. IsSymbol sym => Newtype (form Variant InputFunction) (Variant inputs) => Cons sym (InputFunction e i o) t0 inputs => SProxy sym -> i -> Query form

Set the input value of a form field at the specified label

#resetAll Source

resetAll :: forall form. Query form

Reset all fields to their initial values, and reset the form to its initial pristine state, no touched fields.

#reset Source

reset :: forall o i e t0 sym inputs form. IsSymbol sym => Initial i => Newtype (form Variant InputFunction) (Variant inputs) => Cons sym (InputFunction e i o) t0 inputs => SProxy sym -> Query form

Reset the value of the specified form field to its default value according to the Initial type class.

#modifyValidateAll Source

modifyValidateAll :: forall ifs' ifs form. Newtype (form Record InputFunction) (Record ifs') => HMap WrapField (Record ifs) (Record ifs') => Record ifs -> Query form

Provide a record of input functions to modify all current inputs, and then validate all fields. Similar to calling modifyValidate on every field in the form.

#modifyValidate Source

modifyValidate :: forall o i e t0 sym inputs form. IsSymbol sym => Newtype (form Variant InputFunction) (Variant inputs) => Cons sym (InputFunction e i o) t0 inputs => SProxy sym -> (i -> i) -> Query form

Modify the input value of a form field at the specified label, also triggering validation to run on the field, with the provided function.

#modifyAll Source

modifyAll :: forall ifs' ifs form. Newtype (form Record InputFunction) (Record ifs') => HMap WrapField (Record ifs) (Record ifs') => Record ifs -> Query form

Provide a record of input functions to modify all current inputs. Similar to calling modify on every field in the form.

#modify Source

modify :: forall o i e t0 sym inputs form. IsSymbol sym => Newtype (form Variant InputFunction) (Variant inputs) => Cons sym (InputFunction e i o) t0 inputs => SProxy sym -> (i -> i) -> Query form

Modify the input value of a form field at the specified label with the provided function.

#loadForm_ Source

loadForm_ :: forall form. form Record InputField -> Query form

initialize as an action, so you don't need to specify a Unit result. Use to skip a use of Halogen.action.

#loadForm Source

loadForm :: forall form. form Record InputField -> Query form

Replace all form inputs with a new set of inputs, and re-initialize the form to a new state. Useful to set a new "initial state" for a form, especially when filling a form with data loaded asynchronously.

#asyncSetValidate Source

asyncSetValidate :: forall o i e t0 sym inputs form. IsSymbol sym => Newtype (form Variant InputFunction) (Variant inputs) => Cons sym (InputFunction e i o) t0 inputs => Milliseconds -> SProxy sym -> i -> Query form

Set the input value of a form field at the specified label, while debouncing validation so that it only runs after the specified amount of time has elapsed since the last modification. Useful when you need to avoid expensive validation but do not want to wait for a blur event to validate.

#asyncModifyValidate Source

asyncModifyValidate :: forall o i e t0 sym inputs form. IsSymbol sym => Newtype (form Variant InputFunction) (Variant inputs) => Cons sym (InputFunction e i o) t0 inputs => Milliseconds -> SProxy sym -> (i -> i) -> Query form

Modify the input value of a form field at the specified label, while debouncing validation so that it only runs after the specified amount of time has elapsed since the last modification. Useful when you need to avoid expensive validation but do not want to wait for a blur event to validate.

#andThen Source

andThen :: forall form. Query form -> Query form -> Query form

Perform two Formless actions in sequence. Can be chained arbitrarily. Useful when a field needs to modify itself on change and also trigger validation on one or more other fields, or when a modification on one field should also modify another field.

Re-exports from Formless.Retrieve

#GetTouchedField Source

data GetTouchedField

Data constructor for the getTouchedField function

Constructors

Instances

#GetResultField Source

data GetResultField

Data constructor for the getResultField function

Constructors

Instances

#GetOutput Source

data GetOutput

Data constructor for the getOutput function

Constructors

Instances

#GetInputField Source

data GetInputField

Data constructor for the getInputField function

Constructors

Instances

#GetError Source

data GetError

Data constructor for the getError function

Constructors

Instances

#GetAll Source

type GetAll f = forall r1 r0 form. HMap f r0 r1 => Newtype (form Record FormField) r0 => form Record FormField -> r1

A type representing retrieving all of a particular field with the field's constructor name. For internal use.

#FormFieldLens Source

type FormFieldLens e i o x = forall t0 fields form sym. IsSymbol sym => Newtype (form Record FormField) (Record fields) => Cons sym (FormField e i o) t0 fields => SProxy sym -> Lens' (form Record FormField) x

A type representing a lens onto part of a form field

#FormFieldGet Source

type FormFieldGet e i o x = forall t0 fields form sym. IsSymbol sym => Newtype (form Record FormField) (Record fields) => Cons sym (FormField e i o) t0 fields => SProxy sym -> form Record FormField -> x

A type representing a function to produce a value from a record of form fields given a particular symbol. The result of view from Data.Lens applied with a particular lens to the form.

#getTouchedAll Source

getTouchedAll :: GetAll GetTouchedField

Get the form as a record where all fields are only the touched value

#getTouched Source

getTouched :: forall o i e. FormFieldGet e i o Boolean

Given a form, get the touched field at the specified symbol

#getResultAll Source

getResultAll :: GetAll GetResultField

Get the form as a record where all fields are only the result value

#getResult Source

getResult :: forall o i e. FormFieldGet e i o (FormFieldResult e o)

Given a form, get the result at the specified symbol

#getOutputAll Source

getOutputAll :: GetAll GetOutput

Get the form as a record where all fields are only the output value

#getOutput Source

getOutput :: forall o i e. FormFieldGet e i o (Maybe o)

Given a form, get the output (if it exists) at the specified symbol

#getInputAll Source

getInputAll :: GetAll GetInputField

Get the form as a record where all fields are only the input value

#getInput Source

getInput :: forall o i e. FormFieldGet e i o i

Given a form, get the input at the specified symbol

#getField Source

getField :: forall o i e. FormFieldGet e i o (Record (FormFieldRow e i o))

Given a form, get the field at the specified symbol

#getErrorAll Source

getErrorAll :: GetAll GetError

Get the form as a record where all fields are only the error value

#getError Source

getError :: forall o i e. FormFieldGet e i o (Maybe e)

Given a form, get the error (if it exists) at the specified symbol

#_FieldTouched Source

_FieldTouched :: forall o i e. FormFieldLens e i o Boolean

A lens to operate on the 'touched' field at a given symbol in your form

#_FieldResult Source

_FieldResult :: forall o i e. FormFieldLens e i o (FormFieldResult e o)

A lens to operate on the 'result' field at a given symbol in your form

#_FieldOutput Source

_FieldOutput :: forall o i e t0 fields form sym. IsSymbol sym => Newtype (form Record FormField) (Record fields) => Cons sym (FormField e i o) t0 fields => SProxy sym -> Traversal' (form Record FormField) o

A traversal to operate on the possible output inside the 'result' field at a given symbol in your form

#_FieldInput Source

_FieldInput :: forall o i e. FormFieldLens e i o i

A lens to operate on the input at a given symbol in your form

#_FieldError Source

_FieldError :: forall o i e t0 fields form sym. IsSymbol sym => Newtype (form Record FormField) (Record fields) => Cons sym (FormField e i o) t0 fields => SProxy sym -> Traversal' (form Record FormField) e

A traversal to operate on the possible error inside the 'result' field at a given symbol in your form

#_Field Source

_Field :: forall o i e. FormFieldLens e i o (Record (FormFieldRow e i o))

A lens to operate on the field at a given symbol in your form

Re-exports from Formless.Transform.Record

#WrapField Source

data WrapField

Wrap every field in a record with a particular newtype

Constructors

Instances

#UnwrapField Source

data UnwrapField

Unwrap every newtype in a record filled with newtypes

Constructors

Instances

#wrapRecord Source

wrapRecord :: forall r1 r0. HMap WrapField r0 r1 => r0 -> r1

#wrapInputFunctions Source

wrapInputFunctions :: forall ifs' ifs form. Newtype (form Record InputFunction) (Record ifs') => HMap WrapField (Record ifs) (Record ifs') => Record ifs -> form Record InputFunction

Provided a record, where each field in the record contains a function from input -> input, wraps each function in the InputField type for compatibility with Formless

#wrapInputFields Source

wrapInputFields :: forall is' is form. Newtype (form Record InputField) (Record is') => HMap WrapField (Record is) (Record is') => Record is -> form Record InputField

Provided a record, where each field in the record contains a value of type input, wraps each value in the InputField type for compatibility with Formless

#unwrapRecord Source

unwrapRecord :: forall r1 r0. HMap UnwrapField r0 r1 => r0 -> r1

#unwrapOutputFields Source

unwrapOutputFields :: forall os' os form. Newtype (form Record OutputField) (Record os) => HMap UnwrapField (Record os) (Record os') => form Record OutputField -> Record os'

Provided your form type containing a record of only valid outputs from the result of validation, unwraps the form and every value in the record to provide a record of only the output values.

Re-exports from Formless.Transform.Row

#SProxies Source

type SProxies form = forall inputs row xs. RowToList inputs xs => Newtype (form Record InputField) (Record inputs) => MakeSProxies xs row => Record row

A type to collect constraints necessary to apply to prove that a record of SProxies is compatible with your form type.

#MakeInputFieldsFromRow Source

class MakeInputFieldsFromRow (xs :: RowList) (row :: Row Type) (to :: Row Type) | xs -> to where

The class that provides the Builder implementation to efficiently transform a row into a proper InputFields by wrapping it in newtypes and supplying initial values

Members

Instances

#MakeSProxies Source

class MakeSProxies (xs :: RowList) (to :: Row Type) | xs -> to where

The class used to build up a new record of symbol proxies from an input row list.

Members

Instances

#mkSProxies Source

mkSProxies :: forall row inputs xs form. RowToList inputs xs => Newtype (form Record InputField) (Record inputs) => MakeSProxies xs row => FormProxy form -> Record row

A helper function to produce a record of SProxies given a form spec, to save you the boilerplate of writing them all out.

#mkInputFields Source

mkInputFields :: forall inputs form xs. RowToList inputs xs => Newtype (form Record InputField) (Record inputs) => MakeInputFieldsFromRow xs inputs inputs => FormProxy form -> form Record InputField

A function to transform a row of labels into a InputFields. This allows you to go directly from a custom form newtype to an inputs record without having to fill in any values. Requires that all members have an instance of the Initial type class (all monoidal values do by default, along with some other primitives).

Re-exports from Formless.Types.Form

#U Source

data U e i o

Represents a unit value with the correct number of arguments; largely for internal use.

Constructors

#OutputType Source

type OutputType error input output = output

A type synonym that lets you pick out just the output type from your form row.

#OutputField Source

newtype OutputField error input output

A wrapper to represent only the output type. Used to represent form results at the end of validation.

Constructors

Instances

#InputType Source

type InputType error input output = input

A type synonym that lets you pick out just the input type from your form row.

#InputFunction Source

newtype InputFunction error input output

Represents modifications to input fields

Constructors

Instances

#InputField Source

newtype InputField error input output

A wrapper to represent only the input type. Requires that eq is defined for the input type in order to track dirty states.

Constructors

Instances

#FormProxy Source

data FormProxy (form :: (Row Type -> Type) -> (Type -> Type -> Type -> Type) -> Type)

Create a proxy for your form type, for use with functions that generate records from form proxies.

Constructors

#FormFieldRow Source

type FormFieldRow error input output = (input :: input, result :: FormFieldResult error output, touched :: Boolean)

The row used for the FormField newtype and in lens type signatures

#FormField Source

newtype FormField e i o

The type that we need to record state across the form

Constructors

Instances

#ErrorType Source

type ErrorType error input output = error

A type synonym that lets you pick out just the error type from your form row.

Re-exports from Formless.Types.Query

#ValidStatus Source

data ValidStatus

A type to represent a running debouncer A type to represent validation status

Constructors

Instances

#StateRow Source

type StateRow form r = (dirty :: Boolean, errors :: Int, form :: form Record FormField, submitAttempts :: Int, submitting :: Boolean, validity :: ValidStatus | r)

The component's public state

#State Source

type State form m = Record (StateRow form (internal :: InternalState form m))

The component local state

#Query Source

data Query form

The component query type. See Formless.Query for helpers related to constructing and using these queries.

Constructors

#PublicState Source

type PublicState form = Record (StateRow form ())

The component's public state

#InternalState Source

newtype InternalState form m

A newtype to make easier type errors for end users to read by hiding internal fields

Constructors

Instances

Re-exports from Formless.Validation

#Validation Source

newtype Validation form m error input output

A wrapper to represent the validation function on a form field, which can itself take the form state as its first argument. Inspired in some parts by the Validation type from purescript-polyform by @paluh.

Constructors

Instances

#EmptyValidators Source

data EmptyValidators

The data type used for the noValidation function's heterogenous instance

Constructors

Instances

#runValidation Source

runValidation :: forall o i e m form. Monad m => Validation form m e i o -> form Record FormField -> i -> m (Either e o)

A more verbose but clearer function for running a validation function on its inputs

#noValidation Source

noValidation :: forall xs vs m fields form. Monad m => RowToList fields xs => Newtype (form Record (Validation form m)) (Record vs) => Newtype (form Record InputField) (Record fields) => MapRecordWithIndex xs (ConstMapping EmptyValidators) fields vs => form Record InputField -> form Record (Validation form m)

A function to create a record of validators that simply pass through all inputs for when no validation is needed. Provide this as your validators function.

#hoistFn_ Source

hoistFn_ :: forall o i e m form. Monad m => (i -> o) -> Validation form m e i o

Turn a function from (i -> o) into a proper Validation

#hoistFnME_ Source

hoistFnME_ :: forall o i e m form. Monad m => (i -> m (Either e o)) -> Validation form m e i o

Turn a function from (i -> m (Either e o)) into a proper Validation

#hoistFnME Source

hoistFnME :: forall o i e m form. Monad m => (form Record FormField -> i -> m (Either e o)) -> Validation form m e i o

Turn a function from (form Record FormField -> i -> m (Either e o)) into a proper Validation

#hoistFnE_ Source

hoistFnE_ :: forall o i e m form. Monad m => (i -> Either e o) -> Validation form m e i o

Turn a function from (i -> Either e o) into a proper Validation

#hoistFnE Source

hoistFnE :: forall o i e m form. Monad m => (form Record FormField -> i -> Either e o) -> Validation form m e i o

Turn a function from (form Record FormField -> i -> Either e o) into a proper Validation

#hoistFn Source

hoistFn :: forall o i e m form. Monad m => (form Record FormField -> i -> o) -> Validation form m e i o

Turn a function from (form Record FormField -> i -> o) into a proper Validation