Say I want to have a form with a field, email, which is only required if they have not inserted their phone number. Also, a phone number is only required if they did not send their email address, how would I do it?
I would like to do something like this if necessary NoValid exists.
import play.api.data._ import play.api.data.Forms._ import play.api.data.validation.Constraints._ case class User(email: Option[String] = None, age: Option[Int]) val userForm = Form( mapping( "email" -> email.verifying(requiredNoValid(phoneNumber)), "phoneNumber" -> number.verifying(requiredNoValid(email)) )(User.apply)(User.unapply) )
I created my own solution for this in Play 1.X, but I would like to give up most of this and use the Play 2 forms to do this for me if there is functionality or if there is a way to do this by implementing Validator or Constraint.
myyk
source share