yesod-form 1.6.6 → 1.6.7
raw patch · 3 files changed
+44/−6 lines, 3 files
Files
- ChangeLog.md +4/−0
- Yesod/Form/Functions.hs +39/−5
- yesod-form.cabal +1/−1
ChangeLog.md view
@@ -1,5 +1,9 @@ # ChangeLog for yesod-form +## 1.6.7++* Added equivalent version of `mreqMsg` for `areq` and `wreq` correspondingly [#1628](https://github.com/yesodweb/yesod/pull/1628)+ ## 1.6.6 * Added `mreqMsg` for `mreq` functionality with a configurable MsgValueRequired [#1613](https://github.com/yesodweb/yesod/pull/1613)
Yesod/Form/Functions.hs view
@@ -18,11 +18,13 @@ , wFormToMForm -- * Fields to Forms , wreq+ , wreqMsg , wopt , mreq , mreqMsg , mopt , areq+ , areqMsg , aopt -- * Run a form , runFormPost@@ -124,8 +126,24 @@ -> FieldSettings site -- ^ settings for this field -> Maybe a -- ^ optional default value -> WForm m (FormResult a)-wreq f fs = mFormToWForm . mreq f fs+wreq f fs = wreqMsg f fs MsgValueRequired +-- | Same as @wreq@ but with your own message to be rendered in case the value+-- is not provided.+--+-- This is useful when you have several required fields on the page and you+-- want to differentiate between which fields were left blank. Otherwise the+-- user sees "Value is required" multiple times, which is ambiguous.+--+-- @since 1.6.7+wreqMsg :: (RenderMessage site msg, HandlerSite m ~ site, MonadHandler m)+ => Field m a -- ^ form field+ -> FieldSettings site -- ^ settings for this field+ -> msg -- ^ message to use in case value is Nothing+ -> Maybe a -- ^ optional default value+ -> WForm m (FormResult a)+wreqMsg f fs msg = mFormToWForm . mreqMsg f fs msg+ -- | Converts a form field into monadic form 'WForm'. 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 'wreq' (apart from type of default@@ -247,11 +265,27 @@ -- | Applicative equivalent of 'mreq'. areq :: (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 -> AForm m a-areq a b = formToAForm . liftM (second return) . mreq a b+areq f fs = areqMsg f fs MsgValueRequired++-- | Same as @areq@ but with your own message to be rendered in case the value+-- is not provided.+--+-- This is useful when you have several required fields on the page and you+-- want to differentiate between which fields were left blank. Otherwise the+-- user sees "Value is required" multiple times, which is ambiguous.+--+-- @since 1.6.7+areqMsg :: (RenderMessage site msg, HandlerSite m ~ site, MonadHandler m)+ => Field m a -- ^ form field+ -> FieldSettings site -- ^ settings for this field+ -> msg -- ^ message to use in case value is Nothing+ -> Maybe a -- ^ optional default value+ -> AForm m a+areqMsg f fs msg = formToAForm . liftM (second return) . mreqMsg f fs msg -- | Applicative equivalent of 'mopt'. aopt :: MonadHandler m
yesod-form.cabal view
@@ -1,5 +1,5 @@ name: yesod-form-version: 1.6.6+version: 1.6.7 license: MIT license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>