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

Safe HaskellNone
LanguageHaskell98

Yesod.Form.Fields

Contents

Description

Field functions allow you to easily create and validate forms, cleanly handling the uncertainty of parsing user input.

When possible, the field functions use a specific input type (e.g. "number"), allowing supporting browsers to validate the input before form submission. Browsers can also improve usability with this information; for example, mobile browsers might present a specialized keyboard for an input of type "email" or "number".

See the Yesod book chapter on forms for a broader overview of forms in Yesod.

Synopsis

i18n

Fields

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".

textareaField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Textarea Source

Creates a <textarea> tag whose returned value is wrapped in a Textarea; see Textarea for details.

hiddenField :: (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).

intField :: (Monad m, Integral i, RenderMessage (HandlerSite m) FormMessage) => Field m i Source

Creates a input with type="number" and step=1.

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

Deprecated: timeField currently defaults to an input of type="text". In the next major release, it will default to type="time". To opt in to the new functionality, use timeFieldTypeTime. To keep the existing behavior, use timeFieldTypeText. See 'https://github.com/yesodweb/yesod/pull/874' for details.

An alias for timeFieldTypeText.

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

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.

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.

doubleField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Double Source

Creates a input with type="number" and step=any.

newtype Textarea Source

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.

Constructors

Textarea 

Fields

unTextarea :: Text
 

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 => RenderMessage (HandlerSite m) FormMessage => Field m Bool Source

Creates an input with type="checkbox". While the default boolField implements a radio button so you can differentiate between an empty response (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.

fileField :: (Monad m, RenderMessage (HandlerSite m) FormMessage) => Field m FileInfo Source

Creates an input with type="file".

File AForms

Options

selectFieldList :: (Eq a, RenderMessage site FormMessage, RenderMessage site msg) => [(msg, a)] -> Field (HandlerT site IO) a Source

radioFieldList :: (Eq a, RenderMessage site FormMessage, RenderMessage site msg) => [(msg, a)] -> Field (HandlerT site IO) a Source

checkboxesFieldList :: (Eq a, RenderMessage site FormMessage, RenderMessage site msg) => [(msg, a)] -> Field (HandlerT site IO) [a] Source

multiSelectFieldList :: (Eq a, RenderMessage site FormMessage, RenderMessage site msg) => [(msg, a)] -> Field (HandlerT site IO) [a] Source

data OptionList a Source

Constructors

OptionList 

Fields

olOptions :: [Option a]
 
olReadExternal :: Text -> Maybe a
 

optionsPersistKey :: (YesodPersist site, PersistEntity a, PersistQuery (PersistEntityBackend a), PathPiece (Key a), RenderMessage site msg, YesodPersistBackend site ~ PersistEntityBackend a) => [Filter a] -> [SelectOpt a] -> (a -> msg) -> HandlerT site IO (OptionList (Key a)) Source

An alternative to optionsPersist which returns just the Key instead of the entire Entity.

Since 1.3.2

optionsPairs :: (MonadHandler m, RenderMessage (HandlerSite m) msg) => [(msg, a)] -> m (OptionList a) Source