Skip to content
This repository has been archived by the owner on Jun 15, 2020. It is now read-only.

Commit

Permalink
better example in scalajs doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jto committed May 30, 2016
1 parent a0a653c commit a9bb6ef
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions play-scalajs-example/js/src/main/scala/Validate.scala
@@ -1,7 +1,7 @@
package client

import jto.validation.{Format, Valid, Invalid, VA}
import jto.validation.jsjson.{Rules, Writes}
import jto.validation.{ Format, Valid, Invalid, VA, Formatting }
import jto.validation.jsjson.{ Rules, Writes }
import scala.scalajs.js
import js.annotation.JSExport
import model.User
Expand All @@ -13,7 +13,15 @@ object Validate {
def user(json: js.Dynamic): js.Dictionary[Any] = {
import Rules._, Writes._

val format = Format.gen[js.Dynamic, js.Dynamic, User]
val format =
Formatting[js.Dynamic, js.Dynamic] { __ =>
(
(__ \ "name").format(notEmpty) ~
(__ \ "age").format(min(0) |+| max(130)) ~
(__ \ "email").format(optionR(email), optionW(stringW)) ~
(__ \ "isAlive").format[Boolean]
).unlifted(User.apply, User.unapply _)
}

val validated: VA[User] = format.validate(json)

Expand Down

0 comments on commit a9bb6ef

Please sign in to comment.