Created
December 26, 2010 08:23
-
-
Save softmechanics/755300 to your computer and use it in GitHub Desktop.
Yesod: Using GFormMonad without a type signature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE QuasiQuotes, OverloadedStrings, TemplateHaskell, TypeFamilies #-} | |
import Control.Applicative | |
import Yesod | |
import Yesod.Form.Core | |
data CommentForm = CommentForm | |
{ user :: String | |
, comment :: Textarea | |
, isHtml :: Bool | |
} | |
commentForm = do | |
(user, userField) <- stringField "name:" Nothing | |
(comment, commentField) <- textareaField "comment:" Nothing | |
(isHtml , isHtmlField) <- boolField "html?" Nothing | |
return ( | |
CommentForm <$> user <*> comment <*> isHtml | |
, [$hamlet| | |
%p | |
^fiInput.userField^ | |
%br ^fiInput.commentField^ | |
%br ^fiInput.isHtmlField^ | |
|]) | |
commentForm2 params = CommentForm | |
<$> stringField "name:" Nothing | |
<*> textareaField "comment:" Nothing | |
<*> boolField "html?" Nothing | |
data Test = Test | |
mkYesod "Test" [parseRoutes| | |
/ RootR GET | |
|] | |
getRootR = do | |
((f,w),e) <- runFormMonadGet commentForm | |
defaultLayout [$hamlet| | |
%form!method=GET | |
^w^ | |
%input!type=submit | |
|] | |
instance Yesod Test where approot _ = "" | |
main = basicHandler 3000 Test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment