Play 2.0 Scala: default selected/checked on form e

2019-03-30 23:46发布

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?

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...

Thanks

1条回答
老娘就宠你
2楼-- · 2019-03-31 00:13

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

查看更多
登录 后发表回答