added customErrorMessage to Yesod.Form.Functions to allow the user to overwrite the parse-error messages on fields.
This commit is contained in:
parent
189b3d2bab
commit
d77972ab60
@ -31,6 +31,7 @@ module Yesod.Form.Functions
|
|||||||
, check
|
, check
|
||||||
, checkBool
|
, checkBool
|
||||||
, checkM
|
, checkM
|
||||||
|
, customErrorMessage
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Yesod.Form.Types
|
import Yesod.Form.Types
|
||||||
@ -309,3 +310,8 @@ checkM f field = field
|
|||||||
Right Nothing -> return $ Right Nothing
|
Right Nothing -> return $ Right Nothing
|
||||||
Right (Just a) -> fmap (either (Left . SomeMessage) (Right . Just)) $ f a
|
Right (Just a) -> fmap (either (Left . SomeMessage) (Right . Just)) $ f a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- | Allows you to overwrite the error message on parse error.
|
||||||
|
customErrorMessage :: SomeMessage master -> Field sub master a -> Field sub master a
|
||||||
|
customErrorMessage msg field = field { fieldParse = \ts -> fmap (either
|
||||||
|
(const $ Left msg) Right) $ fieldParse field ts }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user