Created
January 8, 2015 11:41
-
-
Save seratch/cb2653dea15dbeb53852 to your computer and use it in GitHub Desktop.
skinny-validator with multiParams
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
| package controller | |
| import skinny._ | |
| import skinny.validator._ | |
| class RootController extends ApplicationController { | |
| object twoElements extends ValidationRule { | |
| def name = "twoElements" | |
| def isValid(v: Any) = v == null || { | |
| v.isInstanceOf[Seq[_]] && | |
| v.asInstanceOf[Seq[String]].size == 2 | |
| } | |
| } | |
| def form = MapValidator(multiParams).apply(paramKey("foo") is twoElements) | |
| implicit val format = Format.JSON | |
| def index = { | |
| if (form.validate) renderWithFormat(Map("result" -> "ok")) | |
| else renderWithFormat(form.errors) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment