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

Safe Haskell | None

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 |
Enum Enctype |
Eq Enctype |
Monoid Enctype |
ToMarkup Enctype |

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 |
Applicative FormResult |
Show a => Show (FormResult a) |
Monoid m => Monoid (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 |
Read FormMessage |
Show FormMessage |

type Env = Map Text [Text]

type FileEnv = Map Text [FileInfo]

data Ints

Constructors

IntCons Int Ints |
IntSingle Int |

Instances

Show Ints |

# 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 |
Monad m => Functor (AForm m) |
Monad m => Applicative (AForm m) |
(Monad m, Monoid a) => Monoid (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) |

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 () |