Play 2.0 Scala: selected / checked by default on form elements

Can't find anything on the net re: this problem.

I look at github code for select , checkbox and friends, but I completely lose the boat as to how it gets selected / checked by default. What is the deal here?

The case class on which this form is based has a default value for the problem field, but it does nothing. Do I need to apply the default value to the Form entry (mapping ('foo-> boolean))? If so, how?

Ignorance is not bliss, leave some knowledge, if you have it ...

thanks

+4
source share
1 answer

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 completely separated the model from the form. A better approach would be to render the form in some way contain the default values ​​from these scala 2.9.x impenetrable black boxes, known as case classes.

Alas, it does not happen, it seems, I would like to hear otherwise. Call back if you have a product, only provided this answer, because this is the only thing I found during the last two meaningless hours of searching, trial and error; -)

+5
source

Source: https://habr.com/ru/post/1414616/


All Articles