fieldsToDivs
This commit is contained in:
parent
c242af6d0e
commit
2f61ef6d39
@ -24,6 +24,7 @@ module Yesod.Form
|
|||||||
, runFormPost'
|
, runFormPost'
|
||||||
-- * Field/form helpers
|
-- * Field/form helpers
|
||||||
, fieldsToTable
|
, fieldsToTable
|
||||||
|
, fieldsToDivs
|
||||||
, fieldsToPlain
|
, fieldsToPlain
|
||||||
, checkForm
|
, checkForm
|
||||||
-- * Template Haskell
|
-- * Template Haskell
|
||||||
@ -50,7 +51,6 @@ import Control.Monad.Trans.Reader
|
|||||||
import Language.Haskell.TH.Syntax
|
import Language.Haskell.TH.Syntax
|
||||||
import Database.Persist.Base (EntityDef (..), PersistEntity (entityDef))
|
import Database.Persist.Base (EntityDef (..), PersistEntity (entityDef))
|
||||||
import Data.Char (toUpper, isUpper)
|
import Data.Char (toUpper, isUpper)
|
||||||
import Yesod.Widget
|
|
||||||
import Control.Arrow ((&&&))
|
import Control.Arrow ((&&&))
|
||||||
import Data.List (group, sort)
|
import Data.List (group, sort)
|
||||||
|
|
||||||
@ -63,19 +63,32 @@ fieldsToPlain = mapFormXml $ mapM_ fiInput
|
|||||||
fieldsToTable :: FormField sub y a -> Form sub y a
|
fieldsToTable :: FormField sub y a -> Form sub y a
|
||||||
fieldsToTable = mapFormXml $ mapM_ go
|
fieldsToTable = mapFormXml $ mapM_ go
|
||||||
where
|
where
|
||||||
go fi = do
|
go fi = [$hamlet|
|
||||||
wrapWidget (fiInput fi) $ \w -> [$hamlet|
|
|
||||||
%tr.$clazz.fi$
|
%tr.$clazz.fi$
|
||||||
%td
|
%td
|
||||||
%label!for=$fiIdent.fi$ $fiLabel.fi$
|
%label!for=$fiIdent.fi$ $fiLabel.fi$
|
||||||
.tooltip $fiTooltip.fi$
|
.tooltip $fiTooltip.fi$
|
||||||
%td
|
%td
|
||||||
^w^
|
^fiInput.fi^
|
||||||
$maybe fiErrors.fi err
|
$maybe fiErrors.fi err
|
||||||
%td.errors $err$
|
%td.errors $err$
|
||||||
|]
|
|]
|
||||||
clazz fi = if fiRequired fi then "required" else "optional"
|
clazz fi = if fiRequired fi then "required" else "optional"
|
||||||
|
|
||||||
|
-- | Display the label, tooltip, input code and errors in a single div.
|
||||||
|
fieldsToDivs :: FormField sub y a -> Form sub y a
|
||||||
|
fieldsToDivs = mapFormXml $ mapM_ go
|
||||||
|
where
|
||||||
|
go fi = [$hamlet|
|
||||||
|
.$clazz.fi$
|
||||||
|
%label!for=$fiIdent.fi$ $fiLabel.fi$
|
||||||
|
.tooltip $fiTooltip.fi$
|
||||||
|
^fiInput.fi^
|
||||||
|
$maybe fiErrors.fi err
|
||||||
|
%div.errors $err$
|
||||||
|
|]
|
||||||
|
clazz fi = if fiRequired fi then "required" else "optional"
|
||||||
|
|
||||||
runFormGeneric :: Env
|
runFormGeneric :: Env
|
||||||
-> FileEnv
|
-> FileEnv
|
||||||
-> GForm sub y xml a
|
-> GForm sub y xml a
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user