Play 2.0 Scala: default selected/checked on form elements

自闭症网瘾萝莉.ら 提交于 2019-12-03 16:38:28

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?"
)

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 ;-)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!