Created
November 13, 2015 13:30
-
-
Save wolfendale/1309f5a2d29e0bb9cfcc to your computer and use it in GitHub Desktop.
Play Framework Boolean Formatter
This file contains 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
implicit val booleanFormatter: Formatter[Boolean] = new Formatter[Boolean] { | |
override val format = Some(("format.boolean", Nil)) | |
override def bind(key: String, data: Map[String, String]): Either[Seq[FormError], Boolean] = | |
data.get(key) match { | |
case Some(value) => value match { | |
case "true" => Right(true) | |
case "false" => Right(false) | |
case _ => Left(Seq(FormError(key, "error.boolean", Nil))) | |
} | |
case _ => Left(Seq(FormError(key, "error.boolean.empty", Nil))) | |
} | |
override def unbind(key: String, value: Boolean): Map[String, String] = Map(key -> value.toString) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment