Skip to content

Commit

Permalink
df form validation
Browse files Browse the repository at this point in the history
  • Loading branch information
freizl committed May 15, 2012
1 parent f100f74 commit 16bccf5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion README.md
@@ -1,5 +1,6 @@
# TODO # TODO
- [ ] pagedown Markdown intergration. - [X] pagedown Markdown intergration.
+ did some fix to digestive-functor-heist
- [ ] Admin snaplet like admin site of Django?? - [ ] Admin snaplet like admin site of Django??
+ easy for admin models + easy for admin models
- [X] digestive-functors form - [X] digestive-functors form
Expand Down Expand Up @@ -72,3 +73,6 @@ fn :: `Initializer App App App`
and `Initializer App App` is Monad and `Initializer App App` is Monad
when doing glue with do, only last one must have type `Initializer App App App` and others are `Initializer App App a` when doing glue with do, only last one must have type `Initializer App App App` and others are `Initializer App App a`
In other words, MonadState/MonadTransform is a Monad as well. In other words, MonadState/MonadTransform is a Monad as well.

3)
getRequest in Handler
2 changes: 1 addition & 1 deletion snaplets/heist/templates/book.tpl
Expand Up @@ -6,7 +6,7 @@
<h1>Book <name/></h1> <h1>Book <name/></h1>
<p><book/></p> <p><book/></p>


<content></content> <bookContent />


</div> </div>


Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/Book.hs
Expand Up @@ -25,7 +25,7 @@ addBook :: AppHandler ()
addBook = do addBook = do
(view, result) <- runForm "form" bookForm (view, result) <- runForm "form" bookForm
case result of case result of
Just x -> heistLocal ((bindBook x) . (bindSplices [("content", contentSplice x)])) $ render "book" Just x -> heistLocal ((bindBook x) . (bindSplices [("bookContent", contentSplice x)])) $ render "book"
Nothing -> heistLocal (bindDigestiveSplices view) $ render "book-form" Nothing -> heistLocal (bindDigestiveSplices view) $ render "book-form"
where where
bindBook b = bindStrings [ ("book", T.pack $ show b) ] bindBook b = bindStrings [ ("book", T.pack $ show b) ]
Expand Down
10 changes: 9 additions & 1 deletion src/Views/BookForm.hs
Expand Up @@ -3,7 +3,9 @@ module Views.BookForm where


import Control.Applicative ((<$>), (<*>)) import Control.Applicative ((<$>), (<*>))


import Data.Maybe
import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text as T
import Text.Digestive import Text.Digestive


data Lang = EN | CN data Lang = EN | CN
Expand All @@ -17,6 +19,12 @@ data Book = Book


bookForm :: Monad m => Form Text m Book bookForm :: Monad m => Form Text m Book
bookForm = Book bookForm = Book
<$> "name" .: text (Just "Real World Haskell") <$> "name" .: check "Book Name is Required." requiredBookName (text Nothing)
<*> "description" .: text Nothing <*> "description" .: text Nothing
<*> "language" .: choice [(EN, "English"), (CN, "Chinese")] Nothing <*> "language" .: choice [(EN, "English"), (CN, "Chinese")] Nothing

requiredBookName :: Text -> Bool
requiredBookName = not . T.null

checkEmail :: Text -> Bool
checkEmail = isJust . T.find (== '@')

0 comments on commit 16bccf5

Please sign in to comment.