Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play 2.0 form - field "verifying" method is not a member

Practicing what is written here: ScalaForms, I have created the following form:

  val personCreationForm = Form(
    tuple (
        "name" -> nonEmptyText,
        "age" -> number verifying (min(0), max(100))       /*ERROR*/
    ) verifying ("Wrong entry", result => result match {
      case (name, age) => true
    })
  )

However, the error on verifying states that value verifying is not a member of (java.lang.String, play.api.data.Mapping[Int]).

Working with mapping instead of tuple, as in the referenced example, makes no difference. What is wrong here?

like image 424
noncom Avatar asked Apr 21 '12 06:04

noncom


1 Answers

According to Scala operators precedence rules, methods starting with a letter have a lower precedence than others so when you write:

"age" -> number verifying (min(0), max(100))

The compiler builds the following expression:

("age" -> number) verifying (min(0), max(100))

Which is not what you want! You can rewrite it as follows:

"age" -> number.verifying(min(0), max(100))
"age" -> (number verifying (min(0), max(100)))

And the current Play documentation is wrong. Thanks for catching it!

like image 55
Julien Richard-Foy Avatar answered Oct 14 '22 14:10

Julien Richard-Foy