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
Mapping MkFieldState input (FieldState input error output)
#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
(IsSymbol sym, TypeEquals (FieldState input error output) field, Cons sym (FieldState input error output) _1 fields) => MappingWithIndex (MkFieldAction fields action) (Proxy sym) field (FieldAction action input error output)
#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 -> Type
type 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 -> Type
type 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 = Record OptionalFormConfig
Available settings for controlling the form's behavior.
#OptionalFormConfig Source
type OptionalFormConfig :: Row Type
type OptionalFormConfig = (validateOnBlur :: Boolean, validateOnChange :: Boolean, validateOnModify :: Boolean, validateOnMount :: Boolean)
#FormQuery Source
data FormQuery :: (Type -> Type) -> Row Type -> Row Type -> Row Type -> Type -> Type
data 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
andvalidateM
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
#FormAction Source
type FormAction :: Row Type -> Type -> Type
type 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 -> Type
data 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
Raise output
Eval (FormlessAction fields)
#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 -> Type
data 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.
#MkFieldStates Source
class MkFieldStates :: Row Type -> Row Type -> Constraint
class (HMap MkFieldState (Record inputs) (Record fields)) <= MkFieldStates inputs fields | inputs -> fields where
Members
mkFieldStates :: Record inputs -> Record fields
Instances
(HMap MkFieldState (Record inputs) (Record fields)) => MkFieldStates inputs fields
#MkFieldAction Source
newtype MkFieldAction :: Row Type -> Type -> Type
newtype MkFieldAction fields action
Instances
(IsSymbol sym, TypeEquals (FieldState input error output) field, Cons sym (FieldState input error output) _1 fields) => MappingWithIndex (MkFieldAction fields action) (Proxy sym) field (FieldAction action input error output)
#MkFieldActions Source
class MkFieldActions :: Row Type -> Row Type -> Type -> Constraint
class (HMapWithIndex (MkFieldAction fields action) (Record fields) (Record actions)) <= MkFieldActions fields actions action | fields -> actions where
Members
mkFieldActions :: (FormlessAction fields -> action) -> Record fields -> Record actions
Instances
(HMapWithIndex (MkFieldAction fields action) (Record fields) (Record actions)) => MkFieldActions fields actions action
#MkFieldResult Source
data MkFieldResult
Instances
(IsSymbol sym, TypeEquals (FieldState input error output) field, Lacks sym rb, Cons sym (Either error output) rb rc) => FoldingWithIndex MkFieldResult (Proxy sym) (Maybe (Builder (Record ra) (Record rb))) field (Maybe (Builder (Record ra) (Record rc)))
#MkFieldResults Source
class MkFieldResults :: Row Type -> Row Type -> Constraint
class (HFoldlWithIndex MkFieldResult (Maybe (Builder (Record ()) (Record ()))) (Record fields) (Maybe (Builder (Record ()) (Record results)))) <= MkFieldResults fields results | fields -> results where
Members
mkFieldResults :: Record fields -> Maybe (Record results)
Instances
(HFoldlWithIndex MkFieldResult (Maybe (Builder (Record ()) (Record ()))) (Record fields) (Maybe (Builder (Record ()) (Record results)))) => MkFieldResults fields results
#MkFieldOutput Source
data MkFieldOutput
Instances
(IsSymbol sym, TypeEquals (FieldResult input error output) result, Lacks sym rb, Cons sym output rb rc) => FoldingWithIndex MkFieldOutput (Proxy sym) (Maybe (Builder (Record ra) (Record rb))) result (Maybe (Builder (Record ra) (Record rc)))
#MkFieldOutputs Source
class MkFieldOutputs :: Row Type -> Row Type -> Constraint
class (HFoldlWithIndex MkFieldOutput (Maybe (Builder (Record ()) (Record ()))) (Record results) (Maybe (Builder (Record ()) (Record outputs)))) <= MkFieldOutputs results outputs | results -> outputs where
Members
mkFieldOutputs :: Record results -> Maybe (Record outputs)
Instances
(HFoldlWithIndex MkFieldOutput (Maybe (Builder (Record ()) (Record ()))) (Record results) (Maybe (Builder (Record ()) (Record outputs)))) => MkFieldOutputs results outputs
- Modules
- Formless