Skip to content

Instantly share code, notes, and snippets.

@NTCoding
Last active February 13, 2016 12:59
Show Gist options
  • Select an option

  • Save NTCoding/08ad009526194c51faf4 to your computer and use it in GitHub Desktop.

Select an option

Save NTCoding/08ad009526194c51faf4 to your computer and use it in GitHub Desktop.
behavior of "vanilla play conditional mapping"
it should "not contain an error for the conditional validation when there is a field-level error" in {
val data = Map("nonUkResident" -> "true")
val res = form.bind(data)
assert(res.errors.length == 1)
assert(res.errors.head.key === "email")
}
it should "not allow an field-level error message for a conditional validation" in {
val data = Map("nonUkResident" -> "true", "email" -> "abc@gov.uk")
val res = form.bind(data)
assert(res.errors.length == 1)
assert(res.errors.head.key === "")
}
lazy val form = Form(mapping(
"nonUkResident" -> boolean,
"country" -> optional(nonEmptyText),
"email" -> nonEmptyText
)(Model.apply)(Model.unapply).verifying("Error.countryRequired", x => x.nonUkResident && x.country.isDefined))
case class Model(nonUkResident: Boolean, country: Option[String], email: String)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment