diff --git a/Yesod/Form/Core.hs b/Yesod/Form/Core.hs index 4661947f..8a2e9553 100644 --- a/Yesod/Form/Core.hs +++ b/Yesod/Form/Core.hs @@ -14,6 +14,7 @@ module Yesod.Form.Core , fieldsToInput , mapFormXml , checkForm + , checkField , askParams , askFiles , liftForm @@ -241,7 +242,10 @@ type FormField sub y = GForm sub y [FieldInfo sub y] type FormletField sub y a = Maybe a -> FormField sub y a type FormInput sub y = GForm sub y [GWidget sub y ()] --- | FIXME Add some docs, especially about how failures from this function don't show up in the HTML. +-- | Add a validation check to a form. +-- +-- Note that if there is a validation error, this message will /not/ +-- automatically appear on the form; for that, you need to use 'checkField'. checkForm :: (a -> FormResult b) -> GForm s m x a -> GForm s m x b checkForm f (GForm form) = GForm $ do (res, xml, enc) <- form @@ -251,6 +255,10 @@ checkForm f (GForm form) = GForm $ do FormMissing -> FormMissing return (res', xml, enc) +-- | Add a validation check to a 'FormField'. +-- +-- Unlike 'checkForm', the validation error will appear in the generated HTML +-- of the form. checkField :: (a -> Either String b) -> FormField s m a -> FormField s m b checkField f (GForm form) = GForm $ do (res, xml, enc) <- form @@ -260,6 +268,8 @@ checkField f (GForm form) = GForm $ do case f a of Left e -> (FormFailure [e], Just e) Right x -> (FormSuccess x, Nothing) + FormFailure e -> (FormFailure e, Nothing) + FormMissing -> (FormMissing, Nothing) let xml' = case merr of Nothing -> xml diff --git a/Yesod/Form/Profiles.hs b/Yesod/Form/Profiles.hs index 2a65d900..eef0f833 100644 --- a/Yesod/Form/Profiles.hs +++ b/Yesod/Form/Profiles.hs @@ -12,7 +12,6 @@ module Yesod.Form.Profiles , emailFieldProfile , urlFieldProfile , doubleFieldProfile - , fileFieldProfile , parseDate , parseTime , Textarea (..) @@ -20,7 +19,6 @@ module Yesod.Form.Profiles import Yesod.Form.Core import Yesod.Widget -import Yesod.Request import Text.Hamlet import Data.Time (Day, TimeOfDay(..)) import qualified Data.ByteString.Lazy.UTF8 as U @@ -55,9 +53,6 @@ doubleFieldProfile = FieldProfile |] } -fileFieldProfile :: FieldProfile s m FileInfo -fileFieldProfile = undefined -- FIXME - dayFieldProfile :: FieldProfile sub y Day dayFieldProfile = FieldProfile { fpParse = parseDate