flojdek
flojdek

Reputation: 155

Scala Play framework Forms, type not automatically inferred for a tuple parameter

I'm learning to use forms in Play Framework and I have the following problem. I have a case class like this:

case class Part(id:          Option[Int],
                description: String,
                created:     DateTime)

and I'm trying to retrieve/populate it from/to a Play Form defined like this:

val addPartForm = Form(
    mapping(
        "description" -> text
    )(tp => Part.apply(id = None, description = tp._1, created = new DateTime()))
     (pt => (pt.description)))

so basically I'm trying to provide a custom mapping functions as the usual Part.apply and Part.unapply versions are not an exact match/map. When I try to compile this code it gives an error on the tp parameter saying missing parameter type. Why the type for tp can't be inferred automatically? If I provide the type for tp explicitly it does compile. Thank you for your help.

Upvotes: 1

Views: 121

Answers (1)

user908853
user908853

Reputation:

Try describing the resulting tuple as follows:

val addPartForm = Form(
   mapping(
      "description" -> text
   )((description) => Part(id = None, description = description, created = new DateTime()))
   (part => Some(part.description))
)

Upvotes: 1

Related Questions