Skip to content

Instantly share code, notes, and snippets.

@NTCoding
Created February 13, 2016 12:20
Show Gist options
  • Select an option

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

Select an option

Save NTCoding/f0174891b0738d035365 to your computer and use it in GitHub Desktop.
behavior of "conditional mappings"
it should "contain field level errors for fields using conditional mappings" in {
val data = Map("nonUkResident" -> "true")
val res = form.bind(data)
assert(res.errors.length == 2)
assert(res.errors.head.key === "country")
assert(res.errors.tail.head.key === "email")
}
lazy val form = Form(mapping(
"nonUkResident" -> boolean,
"country" -> mandatoryIfTrue("nonUkResident", nonEmptyText),
"email" -> nonEmptyText
)(Model.apply)(Model.unapply))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment