Play 2.0 Scala:默认选中/选中表单元素 [英] Play 2.0 Scala: default selected/checked on form elements
问题描述
在网上找不到任何东西:这个问题.
Can find nothing on the net re: this issue.
I'm looking at the code on github for select, checkbox and friends but am completely missing the boat as to how one gets default selected/checked working. What is the deal here?
问题表格所基于的案例类具有问题字段的默认值,但不会执行任何操作.我是否需要将默认值应用于Form(mapping('foo-> boolean))条目?如果可以,怎么办?
The case class on which form in question is based has a default value for the problem field, but that does nothing. Do I need to apply a default value to the Form(mapping('foo-> boolean)) entry? If so, how?
无知不是幸福,只要有,就放弃一些知识吧……
Ignorance is not bliss, drop some knowledge if you've got it...
谢谢
推荐答案
不理想,但请参见该线程是获得默认值的一种方法.
Not ideal, but see this thread for one way to achieve default values.
@inputRadioGroup(
field = _form("payByCheck").copy(
value=_form("payByCheck").value.map{Some(_)}.getOrElse(Some("false"))
),
options("false"-> "No", "true"-> "Yes"),
'_label-> "Pay By Check?"
)
这里的问题是我们已经将模型与表单完全分离了.更好的方法是将表单映射以某种方式包含来自这些scala 2.9.x不可渗透的黑匣子(称为案例类)的默认值.
The problem here is that we have completely decoupled the model from the form. A better approach would be for the form mapping to somehow contain default values from these scala 2.9.x impenetrable black boxes known as case classes.
可惜,似乎没有发生,我很想听听其他情况.如果您有货,请只提供此答案,因为这是我在搜索,试用和错误的最后两个无意义的小时中发现的唯一内容;-)
Alas, not happening it seems, would love to hear otherwise. Chime in if you've got the goods, only provided this answer as it's the only thing I've found during the last 2 pointless hours of search, trial, and error ;-)
这篇关于Play 2.0 Scala:默认选中/选中表单元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!