yesod-form 1.3.1 → 1.3.2
raw patch · 3 files changed
+40/−5 lines, 3 files
Files
- Yesod/Form/Fields.hs +28/−0
- Yesod/Form/Functions.hs +11/−4
- yesod-form.cabal +1/−1
Yesod/Form/Fields.hs view
@@ -42,6 +42,7 @@ , OptionList (..) , mkOptionList , optionsPersist+ , optionsPersistKey , optionsPairs , optionsEnum ) where@@ -86,6 +87,8 @@ import Data.Attoparsec.Text (Parser, char, string, digit, skipSpace, endOfInput, parseOnly) +import Yesod.Persist.Core+ defaultFormMessage :: FormMessage -> Text defaultFormMessage = englishFormMessage @@ -510,6 +513,31 @@ return $ map (\(Entity key value) -> Option { optionDisplay = mr (toDisplay value) , optionInternalValue = Entity key value+ , optionExternalValue = toPathPiece key+ }) pairs++-- | An alternative to 'optionsPersist' which returns just the @Key@ instead of+-- the entire @Entity@.+--+-- Since 1.3.2+optionsPersistKey+ :: (YesodPersist site+ , PersistEntity a+ , PersistQuery (YesodPersistBackend site (HandlerT site IO))+ , PathPiece (Key a)+ , RenderMessage site msg+ , PersistEntityBackend a ~ PersistMonadBackend (YesodDB site))+ => [Filter a]+ -> [SelectOpt a]+ -> (a -> msg)+ -> HandlerT site IO (OptionList (Key a))++optionsPersistKey filts ords toDisplay = fmap mkOptionList $ do+ mr <- getMessageRender+ pairs <- runDB $ selectList filts ords+ return $ map (\(Entity key value) -> Option+ { optionDisplay = mr (toDisplay value)+ , optionInternalValue = key , optionExternalValue = toPathPiece key }) pairs
Yesod/Form/Functions.hs view
@@ -99,13 +99,18 @@ (x, _, _) <- ask return $ liftM snd x +-- | Converts a form field into monadic form. This field requires a value+-- and will return 'FormFailure' if left empty. mreq :: (RenderMessage site FormMessage, HandlerSite m ~ site, MonadHandler m)- => Field m a- -> FieldSettings site- -> Maybe a+ => Field m a -- ^ form field+ -> FieldSettings site -- ^ settings for this field+ -> Maybe a -- ^ optional default value -> MForm m (FormResult a, FieldView site) mreq field fs mdef = mhelper field fs mdef (\m l -> FormFailure [renderMessage m l MsgValueRequired]) FormSuccess True +-- | Converts a form field into monadic form. This field is optional, i.e.+-- if filled in, it returns 'Just a', if left empty, it returns 'Nothing'.+-- Arguments are the same as for 'mreq' (apart from type of default value). mopt :: (site ~ HandlerSite m, MonadHandler m) => Field m a -> FieldSettings site@@ -155,6 +160,7 @@ , fvRequired = isReq }) +-- | Applicative equivalent of 'mreq'. areq :: (RenderMessage site FormMessage, HandlerSite m ~ site, MonadHandler m) => Field m a -> FieldSettings site@@ -162,6 +168,7 @@ -> AForm m a areq a b = formToAForm . liftM (second return) . mreq a b +-- | Applicative equivalent of 'mopt'. aopt :: MonadHandler m => Field m a -> FieldSettings (HandlerSite m)@@ -218,7 +225,7 @@ _ === _ = False -- in order to avoid timing attacks. return ((res', xml), enctype) --- | Similar to 'runFormPost', except it always ignore the currently available+-- | Similar to 'runFormPost', except it always ignores the currently available -- environment. This is necessary in cases like a wizard UI, where a single -- page will both receive and incoming form and produce a new, blank form. For -- general usage, you can stick with @runFormPost@.
yesod-form.cabal view
@@ -1,5 +1,5 @@ name: yesod-form-version: 1.3.1+version: 1.3.2 license: MIT license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>