Permalink
Browse files

Some FIXMEs

  • Loading branch information...
1 parent 7377919 commit 0c611f58fdb1b066ef2d6e573e56cd0f8acad8d0 @snoyberg snoyberg committed Oct 10, 2010
Showing with 11 additions and 6 deletions.
  1. +11 −1 Yesod/Form/Core.hs
  2. +0 −5 Yesod/Form/Profiles.hs
View
@@ -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
View
@@ -12,15 +12,13 @@ module Yesod.Form.Profiles
, emailFieldProfile
, urlFieldProfile
, doubleFieldProfile
- , fileFieldProfile
, parseDate
, parseTime
, Textarea (..)
) where
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

0 comments on commit 0c611f5

Please sign in to comment.