I am currently developing with Haskell on the Yesod web platform and I need to create a form in one of my webpages. This form must contain several checkboxes, but they need to be grouped into categories. For instance, the user would need to select 3 disciplines in a list of 10 checkboxes, 5 items and of those a maximum of 2 can be weapons.
I have read parts of the book on the Yesod website, and from my understanding I would need to create a custom field to create grouped checkboxes. Unfortunately, I am not very good with Haskell (have just started using it 1-2 weeks ago) and I have some difficulties understanding how I could achieve this. For reference, this is the page that I have read of the book on Yesod's website that talks about custom fields: http://www.yesodweb.com/book/forms
Knowing that, my question would be: how do I create grouped checkboxes in Haskell/Yesod?
EDIT: In the link I have provided, I understand the last two values of the constructor of Field (fieldView and fieldEnctype), it is the first one (fieldParse) that I do not know how to modify for my purpose. Here is the example in the link that I was referencing:
passwordConfirmField :: Field Handler Text
passwordConfirmField = Field
{ fieldParse = \rawVals _fileVals ->
case rawVals of
[a, b]
| a == b -> return $ Right $ Just a
| otherwise -> return $ Left "Passwords don't match"
[] -> return $ Right Nothing
_ -> return $ Left "You must enter two values"
, fieldView = \idAttr nameAttr otherAttrs eResult isReq ->
[whamlet|
<input id=#{idAttr} name=#{nameAttr} *{otherAttrs} type=password>
<div>Confirm:
<input id=#{idAttr}-confirm name=#{nameAttr} *{otherAttrs} type=password>
|]
, fieldEnctype = UrlEncoded
}
So after much research, I have realized that in my case, in order to return the values of the checkboxes that were checked, i need to do:
fieldParse = \rawVals _fileVals ->
return $ Right $ Just rawVals
Since rawVals contains a list of Text of all the values of the checkboxes that were checked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With