Yesod.Form.Core
Contents
Description
Users of the forms library should not need to use this module in general. It is intended only for writing custom forms and form fields.
- data FormResult a
- = FormMissing
- | FormFailure [Text]
- | FormSuccess a
- newtype GForm s m xml a = GForm {
- deform :: FormInner s m (FormResult a, xml, Enctype)
- newFormIdent :: Monad m => StateT Ints m Text
- deeperFormIdent :: Monad m => StateT Ints m ()
- shallowerFormIdent :: Monad m => StateT Ints m ()
- type Env = [(Text, Text)]
- type FileEnv = [(Text, FileInfo)]
- data Enctype
- = UrlEncoded
- | Multipart
- data Ints
- requiredFieldHelper :: IsForm f => FieldProfile (FormSub f) (FormMaster f) (FormType f) -> FormFieldSettings -> Maybe (FormType f) -> f
- optionalFieldHelper :: (IsForm f, Maybe b ~ FormType f) => FieldProfile (FormSub f) (FormMaster f) b -> FormFieldSettings -> Maybe (Maybe b) -> f
- fieldsToInput :: [FieldInfo sub y] -> [GWidget sub y ()]
- mapFormXml :: (xml1 -> xml2) -> GForm s y xml1 a -> GForm s y xml2 a
- checkForm :: (a -> FormResult b) -> GForm s m x a -> GForm s m x b
- checkField :: (a -> Either Text b) -> FormField s m a -> FormField s m b
- askParams :: Monad m => StateT Ints (ReaderT Env m) Env
- askFiles :: Monad m => StateT Ints (ReaderT Env (ReaderT FileEnv m)) FileEnv
- liftForm :: Monad m => m a -> StateT Ints (ReaderT Env (ReaderT FileEnv m)) a
- class IsForm f where
- type FormSub f
- type FormMaster f
- type FormType f
- toForm :: FormInner (FormSub f) (FormMaster f) (FormResult (FormType f), FieldInfo (FormSub f) (FormMaster f), Enctype) -> f
- class RunForm f where
- type RunFormSub f
- type RunFormMaster f
- type RunFormType f
- runFormGeneric :: Env -> FileEnv -> f -> GHandler (RunFormSub f) (RunFormMaster f) (RunFormType f)
- type GFormMonad s m a = WriterT Enctype (FormInner s m) a
- data FieldInfo sub y = FieldInfo {}
- data FormFieldSettings = FormFieldSettings {}
- data FieldProfile sub y a = FieldProfile {}
- type Form sub y = GForm sub y (GWidget sub y ())
- type Formlet sub y a = Maybe a -> Form sub y a
- type FormField sub y = GForm sub y [FieldInfo sub y]
- type FormletField sub y a = Maybe a -> FormField sub y a
- type FormInput sub y = GForm sub y [GWidget sub y ()]
Documentation
data FormResult a Source
A form can produce three different results: there was no data available, the data was invalid, or there was a successful parse.
The Applicative
instance will concatenate the failure messages in two
FormResult
s.
Constructors
FormMissing | |
FormFailure [Text] | |
FormSuccess a |
Instances
Functor FormResult | |
Applicative FormResult | |
Show a => Show (FormResult a) | |
Monoid m => Monoid (FormResult m) |
newtype GForm s m xml a Source
A generic form, allowing you to specifying the subsite datatype, master site datatype, a datatype for the form XML and the return type.
Constructors
GForm | |
Fields
|
The encoding type required by a form. The Show
instance produces values
that can be inserted directly into HTML.
Constructors
UrlEncoded | |
Multipart |
Instances
Show Ints | |
RunForm (GFormMonad s m a) | |
FormResult ~ formResult => IsForm (GFormMonad s m (formResult a, FieldInfo s m)) |
requiredFieldHelper :: IsForm f => FieldProfile (FormSub f) (FormMaster f) (FormType f) -> FormFieldSettings -> Maybe (FormType f) -> fSource
Create a required field (ie, one that cannot be blank) from a
FieldProfile
.
optionalFieldHelper :: (IsForm f, Maybe b ~ FormType f) => FieldProfile (FormSub f) (FormMaster f) b -> FormFieldSettings -> Maybe (Maybe b) -> fSource
Create an optional field (ie, one that can be blank) from a
FieldProfile
.
fieldsToInput :: [FieldInfo sub y] -> [GWidget sub y ()]Source
mapFormXml :: (xml1 -> xml2) -> GForm s y xml1 a -> GForm s y xml2 aSource
Convert the XML in a GForm
.
checkForm :: (a -> FormResult b) -> GForm s m x a -> GForm s m x bSource
Add a validation check to a form.
Note that if there is a validation error, this message will not
automatically appear on the form; for that, you need to use checkField
.
Methods
toForm :: FormInner (FormSub f) (FormMaster f) (FormResult (FormType f), FieldInfo (FormSub f) (FormMaster f), Enctype) -> fSource
Instances
IsForm (FormField s m a) | |
FormResult ~ formResult => IsForm (GFormMonad s m (formResult a, FieldInfo s m)) |
Methods
runFormGeneric :: Env -> FileEnv -> f -> GHandler (RunFormSub f) (RunFormMaster f) (RunFormType f)Source
Instances
RunForm (GFormMonad s m a) | |
RunForm (GForm s m xml a) |
type GFormMonad s m a = WriterT Enctype (FormInner s m) aSource
Data types
Using this as the intermediate XML representation for fields allows us to
write generic field functions and then different functions for producing
actual HTML. See, for example, fieldsToTable
and fieldsToPlain
.
Constructors
FieldInfo | |
Instances
IsForm (FormField s m a) | |
FormResult ~ formResult => IsForm (GFormMonad s m (formResult a, FieldInfo s m)) |
data FieldProfile sub y a Source
A generic definition of a form field that can be used for generating both
required and optional fields. See 'requiredFieldHelper and
optionalFieldHelper
.
Type synonyms
type FormletField sub y a = Maybe a -> FormField sub y aSource