Module

Formless.Action

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

This module exports helpers for working with Formless actions, which you will use in your render function to attach to appropriate fields. Prefer these over using data constructors from the Formless action type. You can also freely extend Formless with more actions of your own using injAction.

#injAction Source

injAction :: forall form act. act -> Action form act

Inject your own action into the Formless component so it can be used in HTML

#set Source

set :: forall form v sym inputs r e i o. IsSymbol sym => Newtype (form Variant InputFunction) (Variant inputs) => Cons sym (InputFunction e i o) r inputs => Proxy sym -> i -> Variant (modify :: form Variant InputFunction | v)

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

[ HE.onValueInput $ Just <<< F.set _name ]

#modify Source

modify :: forall form v sym inputs r e i o. IsSymbol sym => Newtype (form Variant InputFunction) (Variant inputs) => Cons sym (InputFunction e i o) r inputs => Proxy sym -> (i -> i) -> Variant (modify :: form Variant InputFunction | v)

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

[ HE.onChange \_ -> Just $ F.modify _enabled not ]

#validate Source

validate :: forall form v sym us r e i o. IsSymbol sym => Newtype (form Variant U) (Variant us) => Cons sym (U e i o) r us => Proxy sym -> Variant (validate :: form Variant U | v)

Trigger validation on a form field

[ HE.onBlur \_ -> Just $ F.validate _name ]

#setValidate Source

setValidate :: forall form v sym inputs r e i o. IsSymbol sym => Newtype (form Variant InputFunction) (Variant inputs) => Cons sym (InputFunction e i o) r inputs => Proxy sym -> i -> Variant (modifyValidate :: Tuple (Maybe Milliseconds) (form Variant InputFunction) | v)

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

[ HE.onValueInput $ Just <<< F.setValidate _name ]

#modifyValidate Source

modifyValidate :: forall form v sym inputs r e i o. IsSymbol sym => Newtype (form Variant InputFunction) (Variant inputs) => Cons sym (InputFunction e i o) r inputs => Proxy sym -> (i -> i) -> Variant (modifyValidate :: Tuple (Maybe Milliseconds) (form Variant InputFunction) | v)

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

[ HE.onChange \_ -> Just $ F.modifyValidate _enabled not ]

#asyncSetValidate Source

asyncSetValidate :: forall form v sym inputs r e i o. IsSymbol sym => Newtype (form Variant InputFunction) (Variant inputs) => Cons sym (InputFunction e i o) r inputs => Milliseconds -> Proxy sym -> i -> Variant (modifyValidate :: Tuple (Maybe Milliseconds) (form Variant InputFunction) | v)

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.

[ HE.onValueInput $ Just <<< F.asncSetValidate (Milliseconds 300.0) _name ]

#asyncModifyValidate Source

asyncModifyValidate :: forall form v sym inputs r e i o. IsSymbol sym => Newtype (form Variant InputFunction) (Variant inputs) => Cons sym (InputFunction e i o) r inputs => Milliseconds -> Proxy sym -> (i -> i) -> Variant (modifyValidate :: Tuple (Maybe Milliseconds) (form Variant InputFunction) | v)

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.

[ HE.onChange \_ -> Just $ F.asncModifyValidate (Milliseconds 300.0) _enabled not ]

#reset Source

reset :: forall form v sym inputs r e i o. IsSymbol sym => Initial i => Newtype (form Variant InputFunction) (Variant inputs) => Cons sym (InputFunction e i o) r inputs => Proxy sym -> Variant (reset :: form Variant InputFunction | v)

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

[ HE.onClick \_ -> Just $ F.reset _name ]

#setAll Source

setAll :: forall form v is is'. Newtype (form Record InputField) (Record is') => HMap WrapField (Record is) (Record is') => Record is -> Variant (setAll :: Tuple (form Record InputField) Boolean | v)

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

[ HE.onClick \_ -> Just $ F.setAll
    { name: "Default Name"
    , enabled: false
    }
]

#modifyAll Source

modifyAll :: forall form v ifs' ifs. Newtype (form Record InputFunction) (Record ifs') => HMap WrapField (Record ifs) (Record ifs') => Record ifs -> Variant (modifyAll :: Tuple (form Record InputFunction) Boolean | v)

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

[ HE.onClick \_ -> Just $ F.modifyAll
    { name: \str -> "User: " <> str
    , enabled: \bool -> not bool
    }
]

#validateAll Source

validateAll :: forall v. Variant (validateAll :: Unit | v)

Validate all fields in the form, collecting errors

[ HE.onClick \_ -> Just F.validateAll ]

#setValidateAll Source

setValidateAll :: forall form v is' is. Newtype (form Record InputField) (Record is') => HMap WrapField (Record is) (Record is') => Record is -> Variant (setAll :: Tuple (form Record InputField) Boolean | v)

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

[ HE.onClick \_ -> Just $ F.setValidateAll
    { name: "Default Name"
    , enabled: false
    }
]

#modifyValidateAll Source

modifyValidateAll :: forall form v ifs' ifs. Newtype (form Record InputFunction) (Record ifs') => HMap WrapField (Record ifs) (Record ifs') => Record ifs -> Variant (modifyAll :: Tuple (form Record InputFunction) Boolean | v)

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.

[ HE.onClick \_ -> Just $ F.modifyValidateAll
    { name: \str -> "User: " <> str
    , enabled: \bool -> not bool
    }
]

#resetAll Source

resetAll :: forall v. Variant (resetAll :: Unit | v)

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

[ HE.onClick \_ -> Just F.resetAll ]

#submit Source

submit :: forall v. Variant (submit :: Unit | v)

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

[ HE.onClick \_ -> Just F.submit ]

#loadForm Source

loadForm :: forall form v. form Record InputField -> Variant (loadForm :: form Record InputField | v)

Load a form from a set of existing inputs. Useful for when you need to mount Formless, perform some other actions like request data from the server, and then load an existing set of inputs.

[ HE.onClick \_ -> Just $ F.loadForm $ F.wrapInputFields
    { name: ""
    , enabled: false
    }
]