[英]Grouped checkboxes in Haskell/Yesod
I am currently developing with Haskell on the Yesod web platform and I need to create a form in one of my webpages. 我目前正在Yesod网络平台上使用Haskell进行开发,我需要在我的一个网页中创建一个表单。 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. 例如,用户需要在10个复选框的列表中选择3个学科,5个项目,其中最多2个可以是武器。
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. 我在Yesod网站上阅读了本书的部分内容,根据我的理解,我需要创建一个自定义字段来创建分组复选框。 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. 不幸的是,我对Haskell并不是很好(刚刚开始使用它1-2周前)而且我很难理解如何实现这一目标。 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 作为参考,这是我在Yesod网站上读到的关于自定义字段的书的页面: http : //www.yesodweb.com/book/forms
Knowing that, my question would be: how do I create grouped checkboxes in Haskell/Yesod? 知道了,我的问题是:如何在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. 编辑:在我提供的链接中,我理解了Field(fieldView和fieldEnctype)的构造函数的最后两个值,它是第一个(fieldParse),我不知道如何为我的目的进行修改。 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. 由于rawVals包含已检查的复选框的所有值的Text列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.