From c593ded7e5fa885c3a292c4cce4e238de13b5578 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Mon, 9 May 2011 18:43:05 +0300 Subject: [PATCH] Using newIdent properly for IDs --- Yesod/Form/Functions.hs | 18 +++++++++++------- yesod-form.cabal | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Yesod/Form/Functions.hs b/Yesod/Form/Functions.hs index 16acffea..7c0b4c90 100644 --- a/Yesod/Form/Functions.hs +++ b/Yesod/Form/Functions.hs @@ -31,7 +31,7 @@ import Control.Monad.Trans.RWS (ask, get, put, runRWST, tell, evalRWST) import Control.Monad.Trans.Class (lift) import Control.Monad (liftM, join) import Text.Blaze (Html, toHtml) -import Yesod.Handler (GHandler, GGHandler, getRequest, runRequestBody) +import Yesod.Handler (GHandler, GGHandler, getRequest, runRequestBody, newIdent) import Yesod.Widget (GGWidget, whamlet) import Yesod.Request (reqNonce, reqWaiRequest, reqGetParams) import Network.Wai (requestMethod) @@ -78,10 +78,12 @@ askParams = liftM (liftM fst) ask askFiles :: Monad m => Form m (Maybe FileEnv) askFiles = liftM (liftM snd) ask -mreq :: Monad m => Field xml a -> FieldSettings -> Maybe a -> Form m (FormResult a, FieldView xml) +mreq :: Monad m => Field xml a -> FieldSettings -> Maybe a + -> Form (GGHandler sub master m) (FormResult a, FieldView xml) mreq field fs mdef = mhelper field fs mdef (FormFailure ["Value is required"]) FormSuccess True -- TRANS -mopt :: Monad m => Field xml a -> FieldSettings -> Maybe (Maybe a) -> Form m (FormResult (Maybe a), FieldView xml) +mopt :: Monad m => Field xml a -> FieldSettings -> Maybe (Maybe a) + -> Form (GGHandler sub master m) (FormResult (Maybe a), FieldView xml) mopt field fs mdef = mhelper field fs (join mdef) (FormSuccess Nothing) (FormSuccess . Just) False mhelper :: Monad m @@ -91,11 +93,11 @@ mhelper :: Monad m -> FormResult b -- ^ on missing -> (a -> FormResult b) -- ^ on success -> Bool -- ^ is it required? - -> Form m (FormResult b, FieldView xml) + -> Form (GGHandler sub master m) (FormResult b, FieldView xml) mhelper Field {..} FieldSettings {..} mdef onMissing onFound isReq = do mp <- askParams name <- maybe newFormIdent return fsName - theId <- maybe newFormIdent return fsId -- FIXME use widget ident for this + theId <- lift $ maybe (liftM pack newIdent) return fsId let (res, val) = case mp of Nothing -> (FormMissing, maybe "" fieldRender mdef) @@ -115,10 +117,12 @@ mhelper Field {..} FieldSettings {..} mdef onMissing onFound isReq = do , fvRequired = isReq }) -areq :: Monad m => Field xml a -> FieldSettings -> Maybe a -> AForm ([FieldView xml] -> [FieldView xml]) m a +areq :: Monad m => Field xml a -> FieldSettings -> Maybe a + -> AForm ([FieldView xml] -> [FieldView xml]) (GGHandler sub master m) a areq a b = formToAForm . mreq a b -aopt :: Monad m => Field xml a -> FieldSettings -> Maybe (Maybe a) -> AForm ([FieldView xml] -> [FieldView xml]) m (Maybe a) +aopt :: Monad m => Field xml a -> FieldSettings -> Maybe (Maybe a) + -> AForm ([FieldView xml] -> [FieldView xml]) (GGHandler sub master m) (Maybe a) aopt a b = formToAForm . mopt a b runFormGeneric :: Monad m => Form m a -> Maybe (Env, FileEnv) -> m (a, Enctype) diff --git a/yesod-form.cabal b/yesod-form.cabal index 800165cc..9d8e494a 100644 --- a/yesod-form.cabal +++ b/yesod-form.cabal @@ -13,9 +13,9 @@ homepage: http://www.yesodweb.com/ library build-depends: base >= 4 && < 5 - , yesod-core >= 0.8 && < 0.9 + , yesod-core >= 0.8.1 && < 0.9 , time >= 1.1.4 && < 1.3 - , hamlet >= 0.8 && < 0.9 + , hamlet >= 0.8.1 && < 0.9 , persistent >= 0.5 && < 0.6 , yesod-persistent >= 0.1 && < 0.2 , template-haskell