Module

Formless

Package
purescript-halogen-formless
Repository
thomashoneyman/purescript-halogen-formless

#formless Source

formless :: forall config inputs fields actions results outputs query action input output m. MonadEffect m => MkFieldStates inputs fields => MkFieldActions fields actions action => MkFieldResults fields results => MkFieldOutputs results outputs => MkConfig config (InitialFormConfig fields action) => Record config -> Record inputs -> Component (FormQuery query inputs results outputs) (FormContext fields actions input action) (FormOutput fields output) m -> Component query input output m

The Formless higher-order component. Expects a form configuration, the initial input values for each field in the form, and the component that you want to provide FormContext to (ie. your form component).

Please see the Formless README.md and examples directory for a thorough description of this component.

#FieldInput Source

type FieldInput input error output = input

A type synonym which picks the input type from a form field.

#FieldState Source

type FieldState input error output = { initialValue :: input, result :: Maybe (Either error output), value :: input }

A type synonym which represents the current state of a form field.

Instances

#FieldAction Source

type FieldAction action input error output = { handleBlur :: FocusEvent -> action, handleChange :: input -> action, key :: String, modify :: (FieldState input error output -> FieldState input error output) -> action, reset :: action, validate :: action }

A type synonym which represents the available actions that can be called on a form field.

Instances

#FieldResult Source

type FieldResult input error output = Either error output

A type synonym which represents the result of validating the input type of a form field to produce either its error or output.

#FieldOutput Source

type FieldOutput input error output = output

A type synonym which picks the output type from a form field.

#FieldValidation Source

type FieldValidation input error output = input -> Either error output

A type synonm which represents a pure validation function for a form field.

#FieldValidationM Source

type FieldValidationM :: (Type -> Type) -> Type -> Type -> Type -> Typetype FieldValidationM m input error output = input -> m (Either error output)

A type synonm which represents an effectful validation function for a form field.

#validate Source

validate :: forall validators xs r1 r2 r3 inputs results. RowToList validators xs => VariantMapCases xs r1 r2 => Union r1 r3 inputs => Union r2 r3 results => Variant inputs -> Record validators -> Variant results

Validate a variant of form field inputs by providing a record of validation functions, one per possible case in the variant. Used for pure validation.

#validateM Source

validateM :: forall xs r1 r2 r3 inputs validators results m. RowToList validators xs => VariantTraverseCases m xs r1 r2 => Union r1 r3 inputs => Union r2 r3 results => Applicative m => Variant inputs -> Record validators -> m (Variant results)

Validate a variant of form field inputs by providing a record of validation functions, one per possible case in the variant. Used for effectful validation. It is possible to use HalogenM as your validation monad, which gives you full access to your component state (including form fields).

#FormContext Source

type FormContext :: Row Type -> Row Type -> Type -> Type -> Typetype FormContext fields actions input action = { actions :: Record actions, fields :: Record fields, formActions :: FormAction fields action, formState :: FormState, input :: input }

The full form context which is provided to you. It includes any component input you wish to take, along with the current state of the form fields and the form and a set of actions you can use on the form fields or the form.

#FormConfig Source

type FormConfig = { validateOnBlur :: Boolean, validateOnChange :: Boolean, validateOnModify :: Boolean, validateOnMount :: Boolean }

Available settings for controlling the form's behavior.

#FormQuery Source

data FormQuery :: (Type -> Type) -> Row Type -> Row Type -> Row Type -> Type -> Typedata FormQuery query inputs results outputs a

Formless uses queries to notify you when important events happen in your form. You are expected to handle these queries in your handleQuery function so that Formless works correctly.

You can use handleSubmitValidate or handleSubmitValidateM if you only need to handle form submission and validation events.

  • Query Formless has proxied a query from the parent component to you. You are expected to handle the query.

  • Validate A field needs to be validated. You are expected to validate the field and return its validated result. You can use the validate and validateM functions provided for Formless to perform validation.

  • SubmitAttempt The form was submitted, but not all fields passed validation. You are given a record of all form fields along with their validation result.

  • Submit The form was submitted and all fields passed validation. You are given a record of the validated output types for every field in the form.

  • Reset The form was reset to its initial state.

Constructors

#FormState Source

type FormState = { allTouched :: Boolean, errorCount :: Int, submitCount :: Int }

The summary state of the entire form.

#FormAction Source

type FormAction :: Row Type -> Type -> Typetype FormAction fields action = { handleSubmit :: Event -> action, reset :: action, setConfig :: FormConfig -> action, setFields :: Record fields -> action, submit :: action }

Available form-wide actions you can tell Formless to do.

#FormOutput Source

data FormOutput :: Row Type -> Type -> Typedata FormOutput fields output

Formless uses FormOutput to let you notify it of events it should handle.

  • Raise Tell Formless to proxy the provided output to the parent component.

  • Eval Tell Formless to evaluate an action on the form. Actions are provided to you via the FormContext, which gives you actions you can call on individual form fields or on the form as a whole.

Constructors

#eval Source

eval :: forall fields state action slots output m. FormlessAction fields -> HalogenM state action slots (FormOutput fields output) m Unit

Tell Formless to evaluate a Formless action.

#raise Source

raise :: forall fields state action slots output m. output -> HalogenM state action slots (FormOutput fields output) m Unit

A drop-in replacement for Halogen's raise function, which you can use to proxy output through Formless up to the parent component.

#FormlessAction Source

data FormlessAction :: Row Type -> Typedata FormlessAction fields

Internal actions that Formless evaluates to modify the state of the form.

#handleSubmitValidate Source

handleSubmitValidate :: forall inputs fields validators results outputs query state action slots output m a. (Record outputs -> HalogenM state action slots (FormOutput fields output) m Unit) -> (Variant inputs -> Record validators -> Variant results) -> Record validators -> FormQuery query inputs results outputs a -> HalogenM state action slots (FormOutput fields output) m (Maybe a)

A default implementation for handleQuery which only handles successful submission and validation events, used when you only need non-monadic validation. See FormQuery for all available events in Formless.

#handleSubmitValidateM Source

handleSubmitValidateM :: forall inputs fields validators results outputs query state action slots output m a. (Record outputs -> HalogenM state action slots (FormOutput fields output) m Unit) -> (Variant inputs -> Record validators -> HalogenM state action slots (FormOutput fields output) m (Variant results)) -> Record validators -> FormQuery query inputs results outputs a -> HalogenM state action slots (FormOutput fields output) m (Maybe a)

A default implementation for handleQuery which only handles successful submission and validation events, used when you need monadic validation. See FormQuery for all available events in Formless.

#MkConfig Source

class MkConfig :: Row Type -> Type -> Constraintclass (Defaults (Record OptionalFormConfig) (Record config) config') <= MkConfig config config'  where

Members

#MkFieldState Source

data MkFieldState

Instances

#MkFieldStates Source

class MkFieldStates :: Row Type -> Row Type -> Constraintclass (HMap MkFieldState (Record inputs) (Record fields)) <= MkFieldStates inputs fields | inputs -> fields where

Members

Instances

#MkFieldAction Source

newtype MkFieldAction :: Row Type -> Type -> Typenewtype MkFieldAction fields action

Instances

#MkFieldActions Source

class MkFieldActions :: Row Type -> Row Type -> Type -> Constraintclass (HMapWithIndex (MkFieldAction fields action) (Record fields) (Record actions)) <= MkFieldActions fields actions action | fields -> actions where

Members

Instances

#MkFieldResult Source

data MkFieldResult

Instances

#MkFieldResults Source

class MkFieldResults :: Row Type -> Row Type -> Constraintclass (HFoldlWithIndex MkFieldResult (Maybe (Builder (Record ()) (Record ()))) (Record fields) (Maybe (Builder (Record ()) (Record results)))) <= MkFieldResults fields results | fields -> results where

Members

Instances

#MkFieldOutput Source

data MkFieldOutput

Instances

#MkFieldOutputs Source

class MkFieldOutputs :: Row Type -> Row Type -> Constraintclass (HFoldlWithIndex MkFieldOutput (Maybe (Builder (Record ()) (Record ()))) (Record results) (Maybe (Builder (Record ()) (Record outputs)))) <= MkFieldOutputs results outputs | results -> outputs where

Members

Instances

Modules
Formless