Safe Haskell | None |
---|---|
Language | Haskell98 |
Parse forms (and query strings).
Synopsis
- module Yesod.Form.Types
- module Yesod.Form.Functions
- data Option a = Option {}
- data OptionList a = OptionList {
- olOptions :: [Option a]
- olReadExternal :: Text -> Maybe a
- type AutoFocus = Bool
- newtype Textarea = Textarea {
- unTextarea :: Text
- defaultFormMessage :: FormMessage -> Text
- intField :: (Monad m, Integral i, RenderMessage (HandlerSite m) FormMessage) => Field m i
- doubleField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Double
- dayField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Day
- timeField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m TimeOfDay
- timeFieldTypeTime :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m TimeOfDay
- timeFieldTypeText :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m TimeOfDay
- htmlField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Html
- textareaField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Textarea
- hiddenField :: (Monad m, PathPiece p, RenderMessage (HandlerSite m) FormMessage) => Field m p
- textField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Text
- passwordField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Text
- parseDate :: String -> Either FormMessage Day
- parseTime :: Text -> Either FormMessage TimeOfDay
- emailField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Text
- multiEmailField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m [Text]
- searchField :: Monad m => RenderMessage (HandlerSite m) FormMessage => AutoFocus -> Field m Text
- urlField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Text
- selectFieldList :: (Eq a, RenderMessage site FormMessage, RenderMessage site msg) => [(msg, a)] -> Field (HandlerFor site) a
- selectField :: (Eq a, RenderMessage site FormMessage) => HandlerFor site (OptionList a) -> Field (HandlerFor site) a
- multiSelectFieldList :: (Eq a, RenderMessage site msg) => [(msg, a)] -> Field (HandlerFor site) [a]
- multiSelectField :: Eq a => HandlerFor site (OptionList a) -> Field (HandlerFor site) [a]
- radioFieldList :: (Eq a, RenderMessage site FormMessage, RenderMessage site msg) => [(msg, a)] -> Field (HandlerFor site) a
- checkboxesFieldList :: (Eq a, RenderMessage site msg) => [(msg, a)] -> Field (HandlerFor site) [a]
- checkboxesField :: Eq a => HandlerFor site (OptionList a) -> Field (HandlerFor site) [a]
- radioField :: (Eq a, RenderMessage site FormMessage) => HandlerFor site (OptionList a) -> Field (HandlerFor site) a
- boolField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Bool
- checkBoxField :: Monad m => Field m Bool
- mkOptionList :: [Option a] -> OptionList a
- optionsPairs :: (MonadHandler m, RenderMessage (HandlerSite m) msg) => [(msg, a)] -> m (OptionList a)
- optionsEnum :: (MonadHandler m, Show a, Enum a, Bounded a) => m (OptionList a)
- optionsPersist :: (YesodPersist site, PersistQueryRead backend, PathPiece (Key a), RenderMessage site msg, YesodPersistBackend site ~ backend, PersistRecordBackend a backend) => [Filter a] -> [SelectOpt a] -> (a -> msg) -> HandlerFor site (OptionList (Entity a))
- optionsPersistKey :: (YesodPersist site, PersistQueryRead backend, PathPiece (Key a), RenderMessage site msg, backend ~ YesodPersistBackend site, PersistRecordBackend a backend) => [Filter a] -> [SelectOpt a] -> (a -> msg) -> HandlerFor site (OptionList (Key a))
- selectFieldHelper :: (Eq a, RenderMessage site FormMessage) => (Text -> Text -> [(Text, Text)] -> WidgetFor site () -> WidgetFor site ()) -> (Text -> Text -> Bool -> WidgetFor site ()) -> (Text -> Text -> [(Text, Text)] -> Text -> Bool -> Text -> WidgetFor site ()) -> HandlerFor site (OptionList a) -> Field (HandlerFor site) a
- fileField :: Monad m => Field m FileInfo
- fileAFormReq :: (MonadHandler m, RenderMessage (HandlerSite m) FormMessage) => FieldSettings (HandlerSite m) -> AForm m FileInfo
- fileAFormOpt :: MonadHandler m => FieldSettings (HandlerSite m) -> AForm m (Maybe FileInfo)
- module Yesod.Form.Input
Documentation
module Yesod.Form.Types
module Yesod.Form.Functions
Option | |
|
data OptionList a Source #
A structure holding a list of options. Typically you can use a convenience function like mkOptionList
or optionsPairs
instead of creating this directly.
OptionList | |
|
Instances
Functor OptionList Source # | Since 1.4.6 |
Defined in Yesod.Form.Fields fmap :: (a -> b) -> OptionList a -> OptionList b # (<$) :: a -> OptionList b -> OptionList a # |
A newtype wrapper around a Text
whose ToMarkup
instance converts newlines to HTML <br>
tags.
(When text is entered into a <textarea>
, newline characters are used to separate lines.
If this text is then placed verbatim into HTML, the lines won't be separated, thus the need for replacing with <br>
tags).
If you don't need this functionality, simply use unTextarea
to access the raw text.
Instances
Eq Textarea Source # | |
Ord Textarea Source # | |
Defined in Yesod.Form.Fields | |
Read Textarea Source # | |
Show Textarea Source # | |
IsString Textarea Source # | |
Defined in Yesod.Form.Fields fromString :: String -> Textarea # | |
ToJSON Textarea Source # | |
Defined in Yesod.Form.Fields | |
FromJSON Textarea Source # | |
ToMarkup Textarea Source # | |
Defined in Yesod.Form.Fields | |
PersistFieldSql Textarea Source # | |
PersistField Textarea Source # | |
Defined in Yesod.Form.Fields |
defaultFormMessage :: FormMessage -> Text Source #
intField :: (Monad m, Integral i, RenderMessage (HandlerSite m) FormMessage) => Field m i Source #
Creates a input with type="number"
and step=1
.
doubleField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Double Source #
Creates a input with type="number"
and step=any
.
dayField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Day Source #
Creates an input with type="date"
, validating the input using the parseDate
function.
Add the time
package and import the Data.Time.Calendar module to use this function.
timeField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m TimeOfDay Source #
An alias for timeFieldTypeTime
.
timeFieldTypeTime :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m TimeOfDay Source #
Creates an input with type="time"
. Browsers not supporting this type will fallback to a text field, and Yesod will parse the time as described in timeFieldTypeText
.
Add the time
package and import the Data.Time.LocalTime module to use this function.
Since 1.4.2
timeFieldTypeText :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m TimeOfDay Source #
Creates an input with type="text"
, parsing the time from an [H]H:MM[:SS] format, with an optional AM or PM (if not given, AM is assumed for compatibility with the 24 hour clock system).
This function exists for backwards compatibility with the old implementation of timeField
, which used to use type="text"
. Consider using timeField
or timeFieldTypeTime
for improved UX and validation from the browser.
Add the time
package and import the Data.Time.LocalTime module to use this function.
Since 1.4.2
htmlField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Html Source #
Creates a <textarea>
tag whose input is sanitized to prevent XSS attacks and is validated for having balanced tags.
textareaField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Textarea Source #
Monad m, PathPiece p, RenderMessage (HandlerSite m) FormMessage) => Field m p Source #
:: (Creates an input with type="hidden"
; you can use this to store information in a form that users shouldn't see (for example, Yesod stores CSRF tokens in a hidden field).
textField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Text Source #
Creates a input with type="text"
.
passwordField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Text Source #
Creates an input with type="password"
.
emailField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Text Source #
Creates an input with type="email"
. Yesod will validate the email's correctness according to RFC5322 and canonicalize it by removing comments and whitespace (see Text.Email.Validate).
multiEmailField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m [Text] Source #
Creates an input with type="email"
with the multiple attribute; browsers might implement this as taking a comma separated list of emails. Each email address is validated as described in emailField
.
Since 1.3.7
searchField :: Monad m => RenderMessage (HandlerSite m) FormMessage => AutoFocus -> Field m Text Source #
Creates an input with type="search"
. For browsers without autofocus support, a JS fallback is used if AutoFocus
is true.
urlField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Text Source #
Creates an input with type="url"
, validating the URL according to RFC3986.
selectFieldList :: (Eq a, RenderMessage site FormMessage, RenderMessage site msg) => [(msg, a)] -> Field (HandlerFor site) a Source #
Creates a <select>
tag for selecting one option. Example usage:
areq (selectFieldList [("Value 1" :: Text, "value1"),("Value 2", "value2")]) "Which value?" Nothing
selectField :: (Eq a, RenderMessage site FormMessage) => HandlerFor site (OptionList a) -> Field (HandlerFor site) a Source #
Creates a <select>
tag for selecting one option. Example usage:
areq (selectField $ optionsPairs [(MsgValue1, "value1"),(MsgValue2, "value2")]) "Which value?" Nothing
multiSelectFieldList :: (Eq a, RenderMessage site msg) => [(msg, a)] -> Field (HandlerFor site) [a] Source #
Creates a <select>
tag for selecting multiple options.
multiSelectField :: Eq a => HandlerFor site (OptionList a) -> Field (HandlerFor site) [a] Source #
Creates a <select>
tag for selecting multiple options.
radioFieldList :: (Eq a, RenderMessage site FormMessage, RenderMessage site msg) => [(msg, a)] -> Field (HandlerFor site) a Source #
Creates an input with type="radio"
for selecting one option.
checkboxesFieldList :: (Eq a, RenderMessage site msg) => [(msg, a)] -> Field (HandlerFor site) [a] Source #
Creates an input with type="checkbox"
for selecting multiple options.
checkboxesField :: Eq a => HandlerFor site (OptionList a) -> Field (HandlerFor site) [a] Source #
Creates an input with type="checkbox"
for selecting multiple options.
radioField :: (Eq a, RenderMessage site FormMessage) => HandlerFor site (OptionList a) -> Field (HandlerFor site) a Source #
Creates an input with type="radio"
for selecting one option.
boolField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Bool Source #
Creates a group of radio buttons to answer the question given in the message. Radio buttons are used to allow differentiating between an empty response (Nothing
) and a no response (Just False
). Consider using the simpler checkBoxField
if you don't need to make this distinction.
If this field is optional, the first radio button is labeled "<None>", the second "Yes" and the third "No".
If this field is required, the first radio button is labeled "Yes" and the second "No".
(Exact label titles will depend on localization).
checkBoxField :: Monad m => Field m Bool Source #
Creates an input with type="checkbox"
.
While the default
implements a radio button so you
can differentiate between an empty response (boolField
Nothing
) and a no
response (Just False
), this simpler checkbox field returns an empty
response as Just False
.
Note that this makes the field always optional.
mkOptionList :: [Option a] -> OptionList a Source #
Creates an OptionList
, using a Map
to implement the olReadExternal
function.
optionsPairs :: (MonadHandler m, RenderMessage (HandlerSite m) msg) => [(msg, a)] -> m (OptionList a) Source #
Creates an OptionList
from a list of (display-value, internal value) pairs.
optionsEnum :: (MonadHandler m, Show a, Enum a, Bounded a) => m (OptionList a) Source #
Creates an OptionList
from an Enum
, using its Show
instance for the user-facing value.
optionsPersist :: (YesodPersist site, PersistQueryRead backend, PathPiece (Key a), RenderMessage site msg, YesodPersistBackend site ~ backend, PersistRecordBackend a backend) => [Filter a] -> [SelectOpt a] -> (a -> msg) -> HandlerFor site (OptionList (Entity a)) Source #
Selects a list of Entity
s with the given Filter
and SelectOpt
s. The (a -> msg)
function is then used to derive the display value for an OptionList
. Example usage:
Country name Text deriving Eq -- Must derive Eq
data CountryForm = CountryForm { country :: Entity Country } countryNameForm :: AForm Handler CountryForm countryNameForm = CountryForm <$> areq (selectField countries) "Which country do you live in?" Nothing where countries = optionsPersist [] [Asc CountryName] countryName
optionsPersistKey :: (YesodPersist site, PersistQueryRead backend, PathPiece (Key a), RenderMessage site msg, backend ~ YesodPersistBackend site, PersistRecordBackend a backend) => [Filter a] -> [SelectOpt a] -> (a -> msg) -> HandlerFor site (OptionList (Key a)) Source #
An alternative to optionsPersist
which returns just the Key
instead of
the entire Entity
.
Since 1.3.2
:: (Eq a, RenderMessage site FormMessage) | |
=> (Text -> Text -> [(Text, Text)] -> WidgetFor site () -> WidgetFor site ()) | Outermost part of the field |
-> (Text -> Text -> Bool -> WidgetFor site ()) | An option for None if the field is optional |
-> (Text -> Text -> [(Text, Text)] -> Text -> Bool -> Text -> WidgetFor site ()) | Other options |
-> HandlerFor site (OptionList a) | |
-> Field (HandlerFor site) a |
A helper function for constucting selectField
s. You may want to use this when you define your custom selectField
s or radioField
s.
Since: 1.6.2
fileAFormReq :: (MonadHandler m, RenderMessage (HandlerSite m) FormMessage) => FieldSettings (HandlerSite m) -> AForm m FileInfo Source #
fileAFormOpt :: MonadHandler m => FieldSettings (HandlerSite m) -> AForm m (Maybe FileInfo) Source #
module Yesod.Form.Input