Created
June 12, 2014 15:51
-
-
Save vdebergue/6e3ddbae58ba83937245 to your computer and use it in GitHub Desktop.
validate two dependants fields with play framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val locationReadsCreate = new Reads[(String, Option[String])] { | |
| def reads(json: JsValue) = { | |
| val subsidiary = (json \ "subsidiary").asOpt[String] | |
| val location = (json \ "location").asOpt[String] | |
| (subsidiary, location) match { | |
| case (None, _) => JsError(Seq(JsPath() \ "subsidiary" -> Seq(ValidationError("error.path.missing")))) | |
| case (Some("Autre"), None) => JsError(Seq(JsPath() \ "location" -> Seq(locationError))) | |
| case (Some("Autre"), loc @ Some(_)) => JsSuccess(("Autre", loc)) | |
| case (Some(sub), loc @ Some(_)) => JsError(Seq(JsPath() \ "location" -> Seq(locationError))) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment