Found a really amazing way to do this, which looks like itβs missing from the documentation related to the question.
Pull the Play first! formats: import play.api.data.format.Formats._
Then, when defining the display of the form, use the syntax of[]
and then the new val view will look like this:
val clientForm = Form( mapping( "id" -> of[Long], "name" -> text(minLength = 4), "address" -> text(minLength = 4), "city" -> text(minLength = 2), "province" -> text(minLength = 2), "phone" -> optional(text), "email" -> optional(text), "account_id" -> of[Long] )(Client.apply)(Client.unapply) )
Update: using optional ()
After further experimentation, I found that you can mix of[] with Play! optional to match the optional variables defined in your class.
Suppose account_id above is optional ...
"account_id" -> optional(of[Long])
crockpotveggies
source share