yesod-form-1.4.12: Form handling support for Yesod Web Framework

Safe Haskell | None
Language | Haskell98

Yesod.Form.Types

Contents

- Helpers
- Form
- Build forms

Synopsis

- data Enctype
  - = UrlEncoded
  - | Multipart
- data FormResult a
  - = FormMissing
  - | FormFailure [Text]
  - | FormSuccess a
- data FormMessage
  - = MsgInvalidInteger Text
  - | MsgInvalidNumber Text
  - | MsgInvalidEntry Text
  - | MsgInvalidUrl Text
  - | MsgInvalidEmail Text
  - | MsgInvalidTimeFormat
  - | MsgInvalidHour Text
  - | MsgInvalidMinute Text
  - | MsgInvalidSecond Text
  - | MsgInvalidDay
  - | MsgCsrfWarning
  - | MsgValueRequired
  - | MsgInputNotFound Text
  - | MsgSelectNone
  - | MsgInvalidBool Text
  - | MsgBoolYes
  - | MsgBoolNo
  - | MsgDelete
- type Env = Map Text [Text]
- type FileEnv = Map Text [FileInfo]
- data Ints
  - = IntCons Int Ints
  - | IntSingle Int
- type MForm m a = RWST (Maybe (Env, FileEnv), HandlerSite m, [Lang]) Enctype Ints m a
- newtype AForm m a = AForm {
  - unAForm :: (HandlerSite m, [Text]) -> Maybe (Env, FileEnv) -> Ints -> m (FormResult a, [FieldView (HandlerSite m)] -> [FieldView (HandlerSite m)], Ints, Enctype)
  }
- data Field m a = Field {
  - fieldParse :: [Text] -> [FileInfo] -> m (Either (SomeMessage (HandlerSite m)) (Maybe a))
  - fieldView :: FieldViewFunc m a
  - fieldEnctype :: Enctype
  }
- data FieldSettings master = FieldSettings {
  - fsLabel :: SomeMessage master
  - fsTooltip :: Maybe (SomeMessage master)
  - fsId :: Maybe Text
  - fsName :: Maybe Text
  - fsAttrs :: [(Text, Text)]
  }
- data FieldView site = FieldView {
  - fvLabel :: Markup
  - fvTooltip :: Maybe Markup
  - fvId :: Text
  - fvInput :: WidgetT site IO ()
  - fvErrors :: Maybe Markup
  - fvRequired :: Bool
  }
- type FieldViewFunc m a = Text -> Text -> [(Text, Text)] -> Either Text a -> Bool -> WidgetT (HandlerSite m) IO ()

# Helpers

data Enctype #

The encoding type required by a form. The `ToHtml` instance produces values that can be inserted directly into HTML.

Constructors

UrlEncoded |
Multipart |

Instances

Bounded Enctype # |
Methods minBound :: Enctype # maxBound :: Enctype #
Enum Enctype # |
Methods succ :: Enctype -> Enctype # pred :: Enctype -> Enctype # toEnum :: Int -> Enctype # fromEnum :: Enctype -> Int # enumFrom :: Enctype -> [Enctype] # enumFromThen :: Enctype -> Enctype -> [Enctype] # enumFromTo :: Enctype -> Enctype -> [Enctype] # enumFromThenTo :: Enctype -> Enctype -> Enctype -> [Enctype] #
Eq Enctype # |
Methods (==) :: Enctype -> Enctype -> Bool # (/=) :: Enctype -> Enctype -> Bool #
Semigroup Enctype # |
Methods (<>) :: Enctype -> Enctype -> Enctype # sconcat :: NonEmpty Enctype -> Enctype # stimes :: Integral b => b -> Enctype -> Enctype #
Monoid Enctype # |
Methods mempty :: Enctype # mappend :: Enctype -> Enctype -> Enctype # mconcat :: [Enctype] -> Enctype #
ToValue Enctype # |
Methods toValue :: Enctype -> AttributeValue # preEscapedToValue :: Enctype -> AttributeValue #
ToMarkup Enctype # |
Methods toMarkup :: Enctype -> Markup # preEscapedToMarkup :: Enctype -> Markup #

data FormResult a #

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 # |
Methods fmap :: (a -> b) -> FormResult a -> FormResult b # (<$) :: a -> FormResult b -> FormResult a #
Applicative FormResult # |
Methods pure :: a -> FormResult a # (<*>) :: FormResult (a -> b) -> FormResult a -> FormResult b # (*>) :: FormResult a -> FormResult b -> FormResult b # (<*) :: FormResult a -> FormResult b -> FormResult a #
Foldable FormResult # | Since: 1.4.5
Methods fold :: Monoid m => FormResult m -> m # foldMap :: Monoid m => (a -> m) -> FormResult a -> m # foldr :: (a -> b -> b) -> b -> FormResult a -> b # foldr' :: (a -> b -> b) -> b -> FormResult a -> b # foldl :: (b -> a -> b) -> b -> FormResult a -> b # foldl' :: (b -> a -> b) -> b -> FormResult a -> b # foldr1 :: (a -> a -> a) -> FormResult a -> a # foldl1 :: (a -> a -> a) -> FormResult a -> a # toList :: FormResult a -> [a] # null :: FormResult a -> Bool # length :: FormResult a -> Int # elem :: Eq a => a -> FormResult a -> Bool # maximum :: Ord a => FormResult a -> a # minimum :: Ord a => FormResult a -> a # sum :: Num a => FormResult a -> a # product :: Num a => FormResult a -> a #
Traversable FormResult # | Since: 1.4.5
Methods traverse :: Applicative f => (a -> f b) -> FormResult a -> f (FormResult b) # sequenceA :: Applicative f => FormResult (f a) -> f (FormResult a) # mapM :: Monad m => (a -> m b) -> FormResult a -> m (FormResult b) # sequence :: Monad m => FormResult (m a) -> m (FormResult a) #
Show a => Show (FormResult a) # |
Methods showsPrec :: Int -> FormResult a -> ShowS # show :: FormResult a -> String # showList :: [FormResult a] -> ShowS #
Semigroup m => Semigroup (FormResult m) # |
Methods (<>) :: FormResult m -> FormResult m -> FormResult m # sconcat :: NonEmpty (FormResult m) -> FormResult m # stimes :: Integral b => b -> FormResult m -> FormResult m #
Monoid m => Monoid (FormResult m) # |
Methods mempty :: FormResult m # mappend :: FormResult m -> FormResult m -> FormResult m # mconcat :: [FormResult m] -> FormResult m #

data FormMessage #

Constructors

MsgInvalidInteger Text |
MsgInvalidNumber Text |
MsgInvalidEntry Text |
MsgInvalidUrl Text |
MsgInvalidEmail Text |
MsgInvalidTimeFormat |
MsgInvalidHour Text |
MsgInvalidMinute Text |
MsgInvalidSecond Text |
MsgInvalidDay |
MsgCsrfWarning |
MsgValueRequired |
MsgInputNotFound Text |
MsgSelectNone |
MsgInvalidBool Text |
MsgBoolYes |
MsgBoolNo |
MsgDelete |

Instances

Eq FormMessage # |
Methods (==) :: FormMessage -> FormMessage -> Bool # (/=) :: FormMessage -> FormMessage -> Bool #
Read FormMessage # |
Methods readsPrec :: Int -> ReadS FormMessage # readList :: ReadS [FormMessage] # readPrec :: ReadPrec FormMessage # readListPrec :: ReadPrec [FormMessage] #
Show FormMessage # |
Methods showsPrec :: Int -> FormMessage -> ShowS # show :: FormMessage -> String # showList :: [FormMessage] -> ShowS #

type Env = Map Text [Text] #

type FileEnv = Map Text [FileInfo] #

data Ints #

Constructors

IntCons Int Ints |
IntSingle Int |

Instances

Show Ints # |
Methods showsPrec :: Int -> Ints -> ShowS # show :: Ints -> String # showList :: [Ints] -> ShowS #

# Form

type MForm m a = RWST (Maybe (Env, FileEnv), HandlerSite m, [Lang]) Enctype Ints m a #

newtype AForm m a #

Constructors

AForm |
Fields unAForm :: (HandlerSite m, [Text]) -> Maybe (Env, FileEnv) -> Ints -> m (FormResult a, [FieldView (HandlerSite m)] -> [FieldView (HandlerSite m)], Ints, Enctype)

Instances

MonadTrans AForm # |
Methods lift :: Monad m => m a -> AForm m a #
Monad m => Functor (AForm m) # |
Methods fmap :: (a -> b) -> AForm m a -> AForm m b # (<$) :: a -> AForm m b -> AForm m a #
Monad m => Applicative (AForm m) # |
Methods pure :: a -> AForm m a # (<*>) :: AForm m (a -> b) -> AForm m a -> AForm m b # (*>) :: AForm m a -> AForm m b -> AForm m b # (<*) :: AForm m a -> AForm m b -> AForm m a #
(Monad m, Semigroup a) => Semigroup (AForm m a) # |
Methods (<>) :: AForm m a -> AForm m a -> AForm m a # sconcat :: NonEmpty (AForm m a) -> AForm m a # stimes :: Integral b => b -> AForm m a -> AForm m a #
(Monad m, Monoid a) => Monoid (AForm m a) # |
Methods mempty :: AForm m a # mappend :: AForm m a -> AForm m a -> AForm m a # mconcat :: [AForm m a] -> AForm m a #

# Build forms

data Field m a #

Constructors

Field |
Fields fieldParse :: [Text] -> [FileInfo] -> m (Either (SomeMessage (HandlerSite m)) (Maybe a)) fieldView :: FieldViewFunc m a fieldEnctype :: Enctype

data FieldSettings master #

Constructors

FieldSettings |
Fields fsLabel :: SomeMessage master fsTooltip :: Maybe (SomeMessage master) fsId :: Maybe Text fsName :: Maybe Text fsAttrs :: [(Text, Text)]

Instances

IsString (FieldSettings a) # |
Methods fromString :: String -> FieldSettings a #

data FieldView site #

Constructors

FieldView |
Fields fvLabel :: Markup fvTooltip :: Maybe Markup fvId :: Text fvInput :: WidgetT site IO () fvErrors :: Maybe Markup fvRequired :: Bool

type FieldViewFunc m a #

Arguments

= Text | ID
-> Text | Name
-> [(Text, Text)] | Attributes
-> Either Text a | Either (invalid text) or (legitimate result)
-> Bool | Required?
-> WidgetT (HandlerSite m) IO () |