Created
February 4, 2012 12:17
-
-
Save jm-g/1737497 to your computer and use it in GitHub Desktop.
Demonstrate a bug in yesod-form's intField
This file contains 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 TypeFamilies, QuasiQuotes, MultiParamTypeClasses, | |
TemplateHaskell, OverloadedStrings #-} | |
import Control.Applicative | |
import Data.Text | |
import Yesod | |
import Yesod.Form | |
data HelloWorld = HelloWorld | |
instance RenderMessage HelloWorld FormMessage where | |
renderMessage _ _ = defaultFormMessage | |
mkYesod "HelloWorld" [parseRoutes| | |
/ FormR GET POST | |
|] | |
instance Yesod HelloWorld where | |
approot _ = "" | |
data SomeFormData = SFD { field :: Int } | |
deriving Show | |
dataForm :: Html -> MForm HelloWorld HelloWorld (FormResult SomeFormData, Widget) | |
dataForm = renderDivs $ SFD | |
<$> areq intField "Field" Nothing | |
largeInt :: Int | |
largeInt = maxBound | |
getFormR :: Handler RepHtml | |
getFormR = do | |
((_, widget), enctype) <- generateFormPost dataForm | |
defaultLayout [whamlet| | |
<p> Enter a large Int value, e.g. on a 64bit system maxBound :: Int = #{largeInt} | |
<form method=post action=@{FormR} enctype=#{enctype}> | |
^{widget} | |
<input type=submit> | |
|] | |
postFormR :: Handler RepHtml | |
postFormR = do | |
((result, widget), enctype) <- runFormPost dataForm | |
case result of | |
FormSuccess f -> defaultLayout [whamlet|Received #{field f}|] | |
_ -> defaultLayout [whamlet|Something bad happened|] | |
main :: IO () | |
main = warpDebug 3000 HelloWorld |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment