virtualeyes
virtualeyes

Reputation: 11237

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?

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

Upvotes: 4

Views: 1844

Answers (1)

virtualeyes
virtualeyes

Reputation: 11237

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

Upvotes: 5

Related Questions