Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

df form validation

  • Loading branch information...
commit 16bccf5a76413872ddd308a6b0445341940334eb 1 parent f100f74
Haisheng, Wu authored
6 README.md
View
@@ -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
2  snaplets/heist/templates/book.tpl
View
@@ -6,7 +6,7 @@
<h1>Book <name/></h1>
<p><book/></p>
- <content></content>
+ <bookContent />
</div>
2  src/Controllers/Book.hs
View
@@ -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) ]
10 src/Views/BookForm.hs
View
@@ -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 (== '@')
Please sign in to comment.
Something went wrong with that request. Please try again.