From 16bccf5a76413872ddd308a6b0445341940334eb Mon Sep 17 00:00:00 2001 From: "Haisheng.W.WU" Date: Wed, 16 May 2012 00:54:01 +0800 Subject: [PATCH] df form validation --- README.md | 6 +++++- snaplets/heist/templates/book.tpl | 2 +- src/Controllers/Book.hs | 2 +- src/Views/BookForm.hs | 10 +++++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 31399fe..ad6f76d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # TODO - - [ ] pagedown Markdown intergration. + - [X] pagedown Markdown intergration. + + did some fix to digestive-functor-heist - [ ] Admin snaplet like admin site of Django?? + easy for admin models - [X] digestive-functors form @@ -72,3 +73,6 @@ fn :: `Initializer App App App` 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` In other words, MonadState/MonadTransform is a Monad as well. + +3) +getRequest in Handler \ No newline at end of file diff --git a/snaplets/heist/templates/book.tpl b/snaplets/heist/templates/book.tpl index 4f65c1d..ad66e8c 100644 --- a/snaplets/heist/templates/book.tpl +++ b/snaplets/heist/templates/book.tpl @@ -6,7 +6,7 @@

Book

- + diff --git a/src/Controllers/Book.hs b/src/Controllers/Book.hs index f3b5c8d..55a693a 100644 --- a/src/Controllers/Book.hs +++ b/src/Controllers/Book.hs @@ -25,7 +25,7 @@ addBook :: AppHandler () addBook = do (view, result) <- runForm "form" bookForm 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" where bindBook b = bindStrings [ ("book", T.pack $ show b) ] diff --git a/src/Views/BookForm.hs b/src/Views/BookForm.hs index 757160f..b4d5cf6 100644 --- a/src/Views/BookForm.hs +++ b/src/Views/BookForm.hs @@ -3,7 +3,9 @@ module Views.BookForm where import Control.Applicative ((<$>), (<*>)) +import Data.Maybe import Data.Text (Text) +import qualified Data.Text as T import Text.Digestive data Lang = EN | CN @@ -17,6 +19,12 @@ data Book = Book bookForm :: Monad m => Form Text m Book bookForm = Book - <$> "name" .: text (Just "Real World Haskell") + <$> "name" .: check "Book Name is Required." requiredBookName (text Nothing) <*> "description" .: text Nothing <*> "language" .: choice [(EN, "English"), (CN, "Chinese")] Nothing + +requiredBookName :: Text -> Bool +requiredBookName = not . T.null + +checkEmail :: Text -> Bool +checkEmail = isJust . T.find (== '@')