Remove need to mapFormXml externally

This commit is contained in:
Michael Snoyman 2010-08-13 16:28:17 +03:00
parent c7ac7f191c
commit a609f2d046
2 changed files with 8 additions and 7 deletions

View File

@ -9,6 +9,7 @@ module Yesod.Form
GForm
, FormResult (..)
, Enctype
, FormFieldSettings (..)
-- * Type synonyms
, Form
, Formlet
@ -48,13 +49,13 @@ import Control.Arrow ((&&&))
import Data.List (group, sort)
-- | Display only the actual input widget code, without any decoration.
fieldsToPlain :: [FieldInfo sub y] -> GWidget sub y ()
fieldsToPlain = mapM_ fiInput
fieldsToPlain :: FormField sub y a -> Form sub y a
fieldsToPlain = mapFormXml $ mapM_ fiInput
-- | Display the label, tooltip, input code and errors in a single row of a
-- table.
fieldsToTable :: [FieldInfo sub y] -> GWidget sub y ()
fieldsToTable = mapM_ go
fieldsToTable :: FormField sub y a -> Form sub y a
fieldsToTable = mapFormXml $ mapM_ go
where
go fi = do
wrapWidget (fiInput fi) $ \w -> [$hamlet|

View File

@ -52,7 +52,7 @@ getRootR = applyLayoutW $ flip wrapWidget wrapper $ do
addHead [$hamlet|%meta!keywords=haskell|]
handleFormR = do
(res, form, enctype) <- runFormPost $ (,,,,,,,,,)
(res, form, enctype) <- runFormPost $ fieldsToTable $ (,,,,,,,,,)
<$> stringField (FormFieldSettings "My Field" "Some tooltip info" Nothing Nothing) Nothing
<*> stringField ("Another field") (Just "some default text")
<*> intField (FormFieldSettings "A number field" "some nums" Nothing Nothing) (Just 5)
@ -84,8 +84,8 @@ textarea.html
width:300px
height:150px
|]
wrapWidget (fieldsToTable form) $ \h -> [$hamlet|
%form!method=post!enctype=$show.enctype$
wrapWidget form $ \h -> [$hamlet|
%form!method=post!enctype=$enctype$
%table
^h^
%tr