diff --git a/core/play/src/main/scala/views/helper/Helpers.scala b/core/play/src/main/scala/views/helper/Helpers.scala index a0b04073458..9903e4df413 100644 --- a/core/play/src/main/scala/views/helper/Helpers.scala +++ b/core/play/src/main/scala/views/helper/Helpers.scala @@ -34,7 +34,9 @@ package views.html.helper { (args.get('_error) match { case Some(Some(play.api.data.FormError(_, message, args))) => Some(Seq(p.messages(message, args.map(a => translateMsgArg(a)): _*))) - case _ => None + case Some(Some(message: String)) => Some(Seq(p.messages(message))) + case Some(message: String) => Some(Seq(p.messages(message))) + case _ => None }).getOrElse { (if (args.get('_showErrors) match { case Some(false) => false diff --git a/core/play/src/test/scala/views/html/helper/HelpersSpec.scala b/core/play/src/test/scala/views/html/helper/HelpersSpec.scala index f90b34c8b73..f926c4811d6 100644 --- a/core/play/src/test/scala/views/html/helper/HelpersSpec.scala +++ b/core/play/src/test/scala/views/html/helper/HelpersSpec.scala @@ -229,5 +229,31 @@ class HelpersSpec extends Specification { "I am the name of the field" ) } + + "correctly display an error when _error is supplied as String" in { + inputText.apply(Form(single("foo" -> Forms.text))("foo"), '_error -> "Force an error").body must contain( + """
Force an error
""" + ) + } + + "correctly display an error when _error is supplied as Option[String]" in { + inputText.apply(Form(single("foo" -> Forms.text))("foo"), '_error -> Option("Force an error")).body must contain( + """
Force an error
""" + ) + } + + "correctly display an error when _error is supplied as Option[FormError]" in { + inputText + .apply(Form(single("foo" -> Forms.text))("foo"), '_error -> Option(FormError("foo", "Force an error"))) + .body must contain( + """
Force an error
""" + ) + } + + "don't display an error when _error is supplied but is None" in { + inputText.apply(Form(single("foo" -> Forms.text))("foo"), '_error -> None).body must not contain ( + """class="error"""" + ) + } } }