Last active
September 2, 2019 16:19
-
-
Save joelmccracken/62b2d7605d89c07aeb223d255b66cdc2 to your computer and use it in GitHub Desktop.
embed applicative forms in monad form s.t. the error msg and labeling functionaliy from applicative fields are maintained but you can customize the overall feel of the larger form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
joinForm :: Html -> MForm Handler (FormResult Join, Widget) | |
joinForm extra = do | |
let | |
mustAgreeField :: Text -> Field Handler Bool | |
mustAgreeField errorMsg = checkBool id errorMsg checkBoxField | |
accept1Def = areq (mustAgreeField | |
"You must specify that you accept Section 1") | |
"Accept Section 1" Nothing | |
accept2Def = areq (mustAgreeField | |
"You must specify that you accept Section 2") | |
"Accept Section 2" Nothing | |
fullNameDef = areq | |
(checkBool | |
((>0) . length) | |
("You must include your full, legal name" :: Text) | |
textField) | |
"Full Name" | |
Nothing | |
(accept1, accept1Widget) <- renderDivs accept1Def mempty | |
(accept2, accept2Widget) <- renderDivs accept2Def mempty | |
(fullName, fullNameWidget) <- renderDivs fullNameDef mempty | |
let | |
widget = | |
[whamlet| | |
^{extra} | |
<p.my-4> this is a sentence | |
^{accept1Widget} | |
<p.my-4> a sep | |
^{accept2Widget} | |
<p.my-4> another sep | |
^{fullNameWidget} | |
|] | |
joinRes = Join <$> accept1 <*> accept2 <*> fullName | |
return (joinRes, widget) | |
data Join = Join | |
{ joinSignedSection1 :: Bool | |
, joinSignedSection2 :: Bool | |
, joinFullName :: Text | |
} | |
deriving Show |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment