Skip to content

Instantly share code, notes, and snippets.

@seratch
Created January 8, 2015 11:41
Show Gist options
  • Save seratch/cb2653dea15dbeb53852 to your computer and use it in GitHub Desktop.
Save seratch/cb2653dea15dbeb53852 to your computer and use it in GitHub Desktop.
skinny-validator with multiParams
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