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

Safe Haskell | None
Language | Haskell2010

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
  - | MsgInvalidHexColorFormat Text
  - | MsgInvalidDatetimeFormat Text
- type Env = Map Text [Text]
- type FileEnv = Map Text [FileInfo]
- data Ints
  - = IntCons Int Ints
  - | IntSingle Int
- type WForm (m :: Type -> Type) a = MForm (WriterT [FieldView (HandlerSite m)] m) a
- type MForm (m :: Type -> Type) a = RWST (Maybe (Env, FileEnv), HandlerSite m, [Lang]) Enctype Ints m a
- newtype AForm (m :: Type -> Type) a = AForm {
  - unAForm :: (HandlerSite m, [Text]) -> Maybe (Env, FileEnv) -> Ints -> m (FormResult a, [FieldView (HandlerSite m)] -> [FieldView (HandlerSite m)], Ints, Enctype)
  }
- data Field (m :: Type -> Type) 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 :: WidgetFor site ()
  - fvErrors :: Maybe Markup
  - fvRequired :: Bool
  }
- type FieldViewFunc (m :: Type -> Type) a = Text -> Text -> [(Text, Text)] -> Either Text a -> Bool -> WidgetFor (HandlerSite m) ()

# Helpers

data Enctype Source #

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

Constructors

UrlEncoded |
Multipart |

#### Instances

Instances details

ToMarkup Enctype Source # |
Instance details Defined in Yesod.Form.Types Methods toMarkup :: Enctype -> Markup Source # preEscapedToMarkup :: Enctype -> Markup Source #
ToValue Enctype Source # |
Instance details Defined in Yesod.Form.Types Methods toValue :: Enctype -> AttributeValue Source # preEscapedToValue :: Enctype -> AttributeValue Source #
Monoid Enctype Source # |
Instance details Defined in Yesod.Form.Types Methods mempty :: Enctype Source # mappend :: Enctype -> Enctype -> Enctype Source # mconcat :: [Enctype] -> Enctype Source #
Semigroup Enctype Source # |
Instance details Defined in Yesod.Form.Types Methods (<>) :: Enctype -> Enctype -> Enctype Source # sconcat :: NonEmpty Enctype -> Enctype Source # stimes :: Integral b => b -> Enctype -> Enctype Source #
Bounded Enctype Source # |
Instance details Defined in Yesod.Form.Types Methods minBound :: Enctype Source # maxBound :: Enctype Source #
Enum Enctype Source # |

Instance details

Defined in Yesod.Form.Types

Methods

succ :: Enctype -> Enctype Source #

pred :: Enctype -> Enctype Source #

toEnum :: Int -> Enctype Source #

fromEnum :: Enctype -> Int Source #

enumFrom :: Enctype -> [Enctype] Source #

enumFromThen :: Enctype -> Enctype -> [Enctype] Source #

enumFromTo :: Enctype -> Enctype -> [Enctype] Source #

enumFromThenTo :: Enctype -> Enctype -> Enctype -> [Enctype] Source #

Eq Enctype Source # |
Instance details Defined in Yesod.Form.Types Methods (==) :: Enctype -> Enctype -> Bool Source # (/=) :: Enctype -> Enctype -> Bool Source #

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. The `Alternative` instance will choose `FormFailure` before `FormSuccess`, and `FormMissing` last of all.

Constructors

FormMissing |
FormFailure [Text] |
FormSuccess a |

#### Instances

Instances details

Alternative FormResult Source # | Since: 1.4.15
Instance details Defined in Yesod.Form.Types Methods empty :: FormResult a Source # (<|>) :: FormResult a -> FormResult a -> FormResult a Source # some :: FormResult a -> FormResult [a] Source # many :: FormResult a -> FormResult [a] Source #
Applicative FormResult Source # |
Instance details Defined in Yesod.Form.Types Methods pure :: a -> FormResult a Source # (<*>) :: FormResult (a -> b) -> FormResult a -> FormResult b Source # liftA2 :: (a -> b -> c) -> FormResult a -> FormResult b -> FormResult c Source # (*>) :: FormResult a -> FormResult b -> FormResult b Source # (<*) :: FormResult a -> FormResult b -> FormResult a Source #
Functor FormResult Source # |
Instance details Defined in Yesod.Form.Types Methods fmap :: (a -> b) -> FormResult a -> FormResult b Source # (<$) :: a -> FormResult b -> FormResult a Source #
Foldable FormResult Source # | Since: 1.4.5

Instance details

Defined in Yesod.Form.Types

Methods

fold :: Monoid m => FormResult m -> m Source #

foldMap :: Monoid m => (a -> m) -> FormResult a -> m Source #

foldMap' :: Monoid m => (a -> m) -> FormResult a -> m Source #

foldr :: (a -> b -> b) -> b -> FormResult a -> b Source #

foldr' :: (a -> b -> b) -> b -> FormResult a -> b Source #

foldl :: (b -> a -> b) -> b -> FormResult a -> b Source #

foldl' :: (b -> a -> b) -> b -> FormResult a -> b Source #

foldr1 :: (a -> a -> a) -> FormResult a -> a Source #

foldl1 :: (a -> a -> a) -> FormResult a -> a Source #

toList :: FormResult a -> [a] Source #

null :: FormResult a -> Bool Source #

length :: FormResult a -> Int Source #

elem :: Eq a => a -> FormResult a -> Bool Source #

maximum :: Ord a => FormResult a -> a Source #

minimum :: Ord a => FormResult a -> a Source #

sum :: Num a => FormResult a -> a Source #

product :: Num a => FormResult a -> a Source #

Traversable FormResult Source # | Since: 1.4.5
Instance details Defined in Yesod.Form.Types Methods traverse :: Applicative f => (a -> f b) -> FormResult a -> f (FormResult b) Source # sequenceA :: Applicative f => FormResult (f a) -> f (FormResult a) Source # mapM :: Monad m => (a -> m b) -> FormResult a -> m (FormResult b) Source # sequence :: Monad m => FormResult (m a) -> m (FormResult a) Source #
Monoid m => Monoid (FormResult m) Source # |
Instance details Defined in Yesod.Form.Types Methods mempty :: FormResult m Source # mappend :: FormResult m -> FormResult m -> FormResult m Source # mconcat :: [FormResult m] -> FormResult m Source #
Semigroup m => Semigroup (FormResult m) Source # |
Instance details Defined in Yesod.Form.Types Methods (<>) :: FormResult m -> FormResult m -> FormResult m Source # sconcat :: NonEmpty (FormResult m) -> FormResult m Source # stimes :: Integral b => b -> FormResult m -> FormResult m Source #
Show a => Show (FormResult a) Source # |
Instance details Defined in Yesod.Form.Types Methods showsPrec :: Int -> FormResult a -> ShowS Source # show :: FormResult a -> String Source # showList :: [FormResult a] -> ShowS Source #
Eq a => Eq (FormResult a) Source # |
Instance details Defined in Yesod.Form.Types Methods (==) :: FormResult a -> FormResult a -> Bool Source # (/=) :: FormResult a -> FormResult a -> Bool Source #

data FormMessage Source #

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 |
MsgInvalidHexColorFormat Text |
MsgInvalidDatetimeFormat Text |

#### Instances

Instances details

Read FormMessage Source # |
Instance details Defined in Yesod.Form.Types Methods readsPrec :: Int -> ReadS FormMessage Source # readList :: ReadS [FormMessage] Source # readPrec :: ReadPrec FormMessage Source # readListPrec :: ReadPrec [FormMessage] Source #
Show FormMessage Source # |
Instance details Defined in Yesod.Form.Types Methods showsPrec :: Int -> FormMessage -> ShowS Source # show :: FormMessage -> String Source # showList :: [FormMessage] -> ShowS Source #
Eq FormMessage Source # |
Instance details Defined in Yesod.Form.Types Methods (==) :: FormMessage -> FormMessage -> Bool Source # (/=) :: FormMessage -> FormMessage -> Bool Source #

type Env = Map Text [Text] Source #

type FileEnv = Map Text [FileInfo] Source #

data Ints Source #

Constructors

IntCons Int Ints |
IntSingle Int |

#### Instances

Instances details

Show Ints Source # |
Instance details Defined in Yesod.Form.Types Methods showsPrec :: Int -> Ints -> ShowS Source # show :: Ints -> String Source # showList :: [Ints] -> ShowS Source #

# Form

type WForm (m :: Type -> Type) a = MForm (WriterT [FieldView (HandlerSite m)] m) a Source #

`MForm` variant stacking a `WriterT`. The following code example using a monadic form `MForm`:

    formToAForm $ do
      (field1F, field1V) <- mreq textField MsgField1 Nothing
      (field2F, field2V) <- mreq (checkWith field1F textField) MsgField2 Nothing
      (field3F, field3V) <- mreq (checkWith field1F textField) MsgField3 Nothing
      return
        ( MyForm <$> field1F <*> field2F <*> field3F
        , [field1V, field2V, field3V]
        )

Could be rewritten as follows using `WForm`:

    wFormToAForm $ do
      field1F <- wreq textField MsgField1 Nothing
      field2F <- wreq (checkWith field1F textField) MsgField2 Nothing
      field3F <- wreq (checkWith field1F textField) MsgField3 Nothing
      return $ MyForm <$> field1F <*> field2F <*> field3F

Since: 1.4.14

type MForm (m :: Type -> Type) a = RWST (Maybe (Env, FileEnv), HandlerSite m, [Lang]) Enctype Ints m a Source #

newtype AForm (m :: Type -> Type) a Source #

Constructors

AForm |

Fields

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

#### Instances

Instances details

MonadTrans AForm Source # |
Instance details Defined in Yesod.Form.Types Methods lift :: Monad m => m a -> AForm m a Source #
Monad m => Applicative (AForm m) Source # |
Instance details Defined in Yesod.Form.Types Methods pure :: a -> AForm m a Source # (<*>) :: AForm m (a -> b) -> AForm m a -> AForm m b Source # liftA2 :: (a -> b -> c) -> AForm m a -> AForm m b -> AForm m c Source # (*>) :: AForm m a -> AForm m b -> AForm m b Source # (<*) :: AForm m a -> AForm m b -> AForm m a Source #
Monad m => Functor (AForm m) Source # |
Instance details Defined in Yesod.Form.Types Methods fmap :: (a -> b) -> AForm m a -> AForm m b Source # (<$) :: a -> AForm m b -> AForm m a Source #
Monad m => Monad (AForm m) Source # |
Instance details Defined in Yesod.Form.Types Methods (>>=) :: AForm m a -> (a -> AForm m b) -> AForm m b Source # (>>) :: AForm m a -> AForm m b -> AForm m b Source # return :: a -> AForm m a Source #
(Monad m, Monoid a) => Monoid (AForm m a) Source # |
Instance details Defined in Yesod.Form.Types Methods mempty :: AForm m a Source # mappend :: AForm m a -> AForm m a -> AForm m a Source # mconcat :: [AForm m a] -> AForm m a Source #
(Monad m, Semigroup a) => Semigroup (AForm m a) Source # |
Instance details Defined in Yesod.Form.Types Methods (<>) :: AForm m a -> AForm m a -> AForm m a Source # sconcat :: NonEmpty (AForm m a) -> AForm m a Source # stimes :: Integral b => b -> AForm m a -> AForm m a Source #

# Build forms

data Field (m :: Type -> Type) a Source #

Constructors

Field |

Fields

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

data FieldSettings master Source #

Constructors

FieldSettings |

Fields

- fsLabel :: SomeMessage master
- fsTooltip :: Maybe (SomeMessage master)
- fsId :: Maybe Text
- fsName :: Maybe Text
- fsAttrs :: [(Text, Text)]

#### Instances

Instances details

IsString (FieldSettings a) Source # |
Instance details Defined in Yesod.Form.Types Methods fromString :: String -> FieldSettings a Source #

data FieldView site Source #

Constructors

FieldView |

Fields

- fvLabel :: Markup
- fvTooltip :: Maybe Markup
- fvId :: Text
- fvInput :: WidgetFor site ()
- fvErrors :: Maybe Markup
- fvRequired :: Bool

type FieldViewFunc (m :: Type -> Type) a Source #

Arguments

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