In my model all associated accounts are Long not normal integers. However, when handling the Scala form in the new Play! 2.0 I can only validate an Int number in a form and not a Long.
http://www.playframework.org/documentation/2.0/ScalaForms
Take the following form:
val clientForm: Form[Client] = Form(
mapping(
"id" -> number,
"name" -> text(minLength = 4),
"email" -> optional(text),
"phone" -> optional(text),
"address" -> text(minLength = 4),
"city" -> text(minLength = 2),
"province" -> text(minLength = 2),
"account_id" -> number
)
(Client.apply)(Client.unapply)
)
Where you see account_id I want to apply a Long, so how could I cast that in the simplest way possible? The Client.apply syntax is awesome for its simplicity but I’m open to options like mapping. Thanks!
Found a really awesome way to do this that looks like is missing from the documentation I linked in the question.
First, pull in Play! formats:
import play.api.data.format.Formats._Then when defining the Form mapping use
of[]syntaxand then the new form val will look like:
Update: Using optional()
After further experimentation, I discovered that you can mix
of[]with the Play!optionalto meet the optional variables defined in your class.So assume that the
account_idabove is optional…