Yesod.Form.Types

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 #

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

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

Constructors

FormMissing |
FormFailure [Text] |
FormSuccess a |

#### Instances

Instances details

Alternative FormResult # | Since: 1.4.15
Instance details Defined in Yesod.Form.Types Methods empty :: FormResult a # (<|>) :: FormResult a -> FormResult a -> FormResult a # some :: FormResult a -> FormResult [a] # many :: FormResult a -> FormResult [a] #
Applicative FormResult # |
Instance details Defined in Yesod.Form.Types Methods pure :: a -> FormResult a # (<*>) :: FormResult (a -> b) -> FormResult a -> FormResult b # liftA2 :: (a -> b -> c) -> FormResult a -> FormResult b -> FormResult c # (*>) :: FormResult a -> FormResult b -> FormResult b # (<*) :: FormResult a -> FormResult b -> FormResult a #
Functor FormResult # |
Instance details Defined in Yesod.Form.Types Methods fmap :: (a -> b) -> FormResult a -> FormResult b # (<$) :: a -> FormResult b -> FormResult a #
Foldable FormResult # | Since: 1.4.5
Instance details Defined in Yesod.Form.Types Methods fold :: Monoid m => FormResult m -> m # foldMap :: Monoid m => (a -> m) -> FormResult a -> 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
Instance details Defined in Yesod.Form.Types 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) #
Monoid m => Monoid (FormResult m) # |
Instance details Defined in Yesod.Form.Types Methods mempty :: FormResult m # mappend :: FormResult m -> FormResult m -> FormResult m # mconcat :: [FormResult m] -> FormResult m #
Semigroup m => Semigroup (FormResult m) # |
Instance details Defined in Yesod.Form.Types Methods (<>) :: FormResult m -> FormResult m -> FormResult m # sconcat :: NonEmpty (FormResult m) -> FormResult m # stimes :: Integral b => b -> FormResult m -> FormResult m #
Show a => Show (FormResult a) # |
Instance details Defined in Yesod.Form.Types Methods showsPrec :: Int -> FormResult a -> ShowS # show :: FormResult a -> String # showList :: [FormResult a] -> ShowS #
Eq a => Eq (FormResult a) # |
Instance details Defined in Yesod.Form.Types Methods (==) :: FormResult a -> FormResult a -> Bool # (/=) :: FormResult a -> FormResult a -> Bool #

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

#### Instances

Instances details

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

type Env = Map Text [Text] #

type FileEnv = Map Text [FileInfo] #

data Ints #

Constructors

IntCons Int Ints |
IntSingle Int |

#### Instances

Instances details

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

# Form

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

`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 #

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

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

# Build forms

data Field (m :: Type -> Type) 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

Instances details

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

data FieldView site #

Constructors

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

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

Arguments

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