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

View File

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