Skip to content
Browse files

Merge pull request #1264 from jroper/1264-no-validate-on-fill

Form.fill still calls validation function
  • Loading branch information...
2 parents fac8821 + a75981b commit 3bebfa7c1226a438a687ec9a0a3e5c23e5aefa09 @huntc huntc committed Dec 18, 2013
View
126 framework/src/play/src/main/scala/play/api/data/Form.scala
@@ -104,7 +104,7 @@ case class Form[T](mapping: Mapping[T], data: Map[String, String], errors: Seq[F
*/
def fill(value: T): Form[T] = {
val result = mapping.unbind(value)
- this.copy(data = result._1, value = Some(value))
+ this.copy(data = result, value = Some(value))
}
/**
@@ -114,7 +114,7 @@ case class Form[T](mapping: Mapping[T], data: Map[String, String], errors: Seq[F
* @return a copy of this form filled with the new data
*/
def fillAndValidate(value: T): Form[T] = {
- val result = mapping.unbind(value)
+ val result = mapping.unbindAndValidate(value)
this.copy(data = result._1, errors = result._2, value = Some(value))
}
@@ -459,9 +459,17 @@ trait Mapping[T] {
* Unbinds this field, i.e. transforms a concrete value to plain data.
*
* @param value the value to unbind
- * @return either the plain data or a set of errors, if the unbinding failed
+ * @return the plain data
*/
- def unbind(value: T): (Map[String, String], Seq[FormError])
+ def unbind(value: T): Map[String, String]
+
+ /**
+ * Unbinds this field, i.e. transforms a concrete value to plain data, and applies validation.
+ *
+ * @param value the value to unbind
+ * @return the plain data and any errors in the plain data
+ */
+ def unbindAndValidate(value: T): (Map[String, String], Seq[FormError])
/**
* Constructs a new Mapping based on this one, adding a prefix to the key.
@@ -601,10 +609,18 @@ case class WrappedMapping[A, B](wrapped: Mapping[A], f1: A => B, f2: B => A, val
* Unbinds this field, i.e. transforms a concrete value to plain data.
*
* @param value the value to unbind
- * @return either the plain data or a set of errors, if the unbinding failed
+ * @return the plain data
*/
- def unbind(value: B): (Map[String, String], Seq[FormError]) = {
- (wrapped.unbind(f2(value))._1, collectErrors(value))
+ def unbind(value: B): Map[String, String] = wrapped.unbind(f2(value))
+
+ /**
+ * Unbinds this field, i.e. transforms a concrete value to plain data, and applies validation.
+ *
+ * @param value the value to unbind
+ * @return the plain data and any errors in the plain data
+ */
+ def unbindAndValidate(value: B): (Map[String, String], Seq[FormError]) = {
+ (wrapped.unbindAndValidate(f2(value))._1, collectErrors(value))
}
/**
@@ -699,10 +715,21 @@ case class RepeatedMapping[T](wrapped: Mapping[T], val key: String = "", val con
* Unbinds this field, i.e. transforms a concrete value to plain data.
*
* @param value the value to unbind
- * @return either the plain data or a set of errors, if the unbinding failed
+ * @return the plain data
+ */
+ def unbind(value: List[T]): Map[String, String] = {
+ val datas = value.zipWithIndex.map { case (t, i) => wrapped.withPrefix(key + "[" + i + "]").unbind(t) }
+ datas.foldLeft(Map.empty[String, String])(_ ++ _)
+ }
+
+ /**
+ * Unbinds this field, i.e. transforms a concrete value to plain data, and applies validation.
+ *
+ * @param value the value to unbind
+ * @return the plain data and any errors in the plain data
*/
- def unbind(value: List[T]): (Map[String, String], Seq[FormError]) = {
- val (datas, errors) = value.zipWithIndex.map { case (t, i) => wrapped.withPrefix(key + "[" + i + "]").unbind(t) }.unzip
+ def unbindAndValidate(value: List[T]): (Map[String, String], Seq[FormError]) = {
+ val (datas, errors) = value.zipWithIndex.map { case (t, i) => wrapped.withPrefix(key + "[" + i + "]").unbindAndValidate(t) }.unzip
(datas.foldLeft(Map.empty[String, String])(_ ++ _), errors.flatten ++ collectErrors(value))
}
@@ -772,12 +799,22 @@ case class OptionalMapping[T](wrapped: Mapping[T], val constraints: Seq[Constrai
/**
* Unbinds this field, i.e. transforms a concrete value to plain data.
*
- * @param value The value to unbind.
- * @return Either the plain data or a set of error if the unbinding failed.
+ * @param value the value to unbind
+ * @return the plain data
*/
- def unbind(value: Option[T]): (Map[String, String], Seq[FormError]) = {
+ def unbind(value: Option[T]): Map[String, String] = {
+ value.map(wrapped.unbind).getOrElse(Map.empty)
+ }
+
+ /**
+ * Unbinds this field, i.e. transforms a concrete value to plain data, and applies validation.
+ *
+ * @param value the value to unbind
+ * @return the plain data and any errors in the plain data
+ */
+ def unbindAndValidate(value: Option[T]): (Map[String, String], Seq[FormError]) = {
val errors = collectErrors(value)
- value.map(wrapped.unbind(_)).map(r => r._1 -> (r._2 ++ errors)).getOrElse(Map.empty -> errors)
+ value.map(wrapped.unbindAndValidate).map(r => r._1 -> (r._2 ++ errors)).getOrElse(Map.empty -> errors)
}
/**
@@ -850,9 +887,19 @@ case class FieldMapping[T](val key: String = "", val constraints: Seq[Constraint
* Unbinds this field, i.e. transforms a concrete value to plain data.
*
* @param value the value to unbind
- * @return either the plain data or a set of errors, if unbinding failed
+ * @return the plain data
+ */
+ def unbind(value: T): Map[String, String] = {
+ binder.unbind(key, value)
+ }
+
+ /**
+ * Unbinds this field, i.e. transforms a concrete value to plain data, and applies validation.
+ *
+ * @param value the value to unbind
+ * @return the plain data and any errors in the plain data
*/
- def unbind(value: T): (Map[String, String], Seq[FormError]) = {
+ def unbindAndValidate(value: T): (Map[String, String], Seq[FormError]) = {
binder.unbind(key, value) -> collectErrors(value)
}
@@ -899,50 +946,3 @@ trait ObjectMapping {
}
}
-
-/**
- * Represents an object binding (ie. a binding for several fields).
- *
- * This is used for objects with one field. Other versions exist, e.g. `ObjectMapping2`, `ObjectMapping3`, etc.
- *
- * @tparam T the complex object type
- * @tparam A the first field type
- * @param apply a constructor function that creates a instance of `T` using field `A`
- * @param fa a mapping for field `A`
- * @param constraints constraints associated with this mapping
- */
-case class ObjectMapping1[R, A1](apply: Function1[A1, R], unapply: Function1[R, Option[(A1)]], f1: (String, Mapping[A1]), val key: String = "", val constraints: Seq[Constraint[R]] = Nil) extends Mapping[R] with ObjectMapping {
-
- val field1 = f1._2.withPrefix(f1._1).withPrefix(key)
-
- def bind(data: Map[String, String]) = {
- merge(field1.bind(data)) match {
- case Left(errors) => Left(errors)
- case Right(values) => {
- applyConstraints(apply(
-
- values(0).asInstanceOf[A1]))
- }
- }
- }
-
- def unbind(value: R) = {
- unapply(value).map { fields =>
- val (v1) = fields
- val a1 = field1.unbind(v1)
-
- (a1._1) ->
- (a1._2)
- }.getOrElse(Map.empty -> Seq(FormError(key, "unbind.failed")))
- }
-
- def withPrefix(prefix: String) = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
-
- def verifying(addConstraints: Constraint[R]*) = {
- this.copy(constraints = constraints ++ addConstraints.toSeq)
- }
-
- val mappings = Seq(this) ++ field1.mappings
-
-}
-
View
699 framework/src/play/src/main/scala/play/core/hidden/ObjectMappings.scala
@@ -6,6 +6,109 @@ package play.api.data
import format._
import validation._
+/*
+ Everything below this line is generated by this magical shell script:
+
+#!/bin/sh
+exec scala -savecompiled "$0" $@
+!#
+
+def generate(times: Int) = {
+
+ def g(format: String, sep: String) = (for (i <- 1 to times) yield format.replaceAll("%", i.toString).replaceAll("#", (i - 1).toString)).mkString(sep)
+
+ def aParams = g("A%", ", ")
+
+s"""
+case class ObjectMapping$times[R, $aParams](apply: Function$times[$aParams, R], unapply: Function1[R, Option[($aParams)]], ${g("f%: (String, Mapping[A%])", ", ")}, val key: String = "", val constraints: Seq[Constraint[R]] = Nil) extends Mapping[R] with ObjectMapping {
+
+ ${g("val field% = f%._2.withPrefix(f%._1).withPrefix(key)", "\n\n ")}
+
+ def bind(data: Map[String, String]): Either[Seq[FormError], R] = {
+ merge(${g("field%.bind(data)", ", ")}) match {
+ case Left(errors) => Left(errors)
+ case Right(values) => {
+ applyConstraints(apply(
+ ${g("values(#).asInstanceOf[A%]", ",\n ")}
+ ))
+ }
+ }
+ }
+
+ def unbind(value: R): Map[String, String] = {
+ unapply(value).map { fields =>
+ val (${g("v%", ", ")}) = fields
+ ${g("field%.unbind(v%)", " ++ ")}
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
+ unapply(value).map { fields =>
+ val (${g("v%", ", ")}) = fields
+ ${g("val a% = field%.unbindAndValidate(v%)", "\n ")}
+
+ (${g("a%._1", " ++ ")}) ->
+ (${g("a%._2", " ++ ")})
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
+ }
+
+ def withPrefix(prefix: String): ObjectMapping$times[R, $aParams] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
+
+ def verifying(addConstraints: Constraint[R]*): ObjectMapping$times[R, $aParams] = {
+ this.copy(constraints = constraints ++ addConstraints.toSeq)
+ }
+
+ val mappings = Seq(this) ++ ${g("field%.mappings", " ++ ")}
+
+}
+"""
+}
+
+println((for (i <- 1 to 18) yield generate(i)).mkString(""))
+ */
+
+case class ObjectMapping1[R, A1](apply: Function1[A1, R], unapply: Function1[R, Option[(A1)]], f1: (String, Mapping[A1]), val key: String = "", val constraints: Seq[Constraint[R]] = Nil) extends Mapping[R] with ObjectMapping {
+
+ val field1 = f1._2.withPrefix(f1._1).withPrefix(key)
+
+ def bind(data: Map[String, String]): Either[Seq[FormError], R] = {
+ merge(field1.bind(data)) match {
+ case Left(errors) => Left(errors)
+ case Right(values) => {
+ applyConstraints(apply(
+ values(0).asInstanceOf[A1]
+ ))
+ }
+ }
+ }
+
+ def unbind(value: R): Map[String, String] = {
+ unapply(value).map { fields =>
+ val (v1) = fields
+ field1.unbind(v1)
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
+ unapply(value).map { fields =>
+ val (v1) = fields
+ val a1 = field1.unbindAndValidate(v1)
+
+ (a1._1) ->
+ (a1._2)
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
+ }
+
+ def withPrefix(prefix: String): ObjectMapping1[R, A1] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
+
+ def verifying(addConstraints: Constraint[R]*): ObjectMapping1[R, A1] = {
+ this.copy(constraints = constraints ++ addConstraints.toSeq)
+ }
+
+ val mappings = Seq(this) ++ field1.mappings
+
+}
+
case class ObjectMapping2[R, A1, A2](apply: Function2[A1, A2, R], unapply: Function1[R, Option[(A1, A2)]], f1: (String, Mapping[A1]), f2: (String, Mapping[A2]), val key: String = "", val constraints: Seq[Constraint[R]] = Nil) extends Mapping[R] with ObjectMapping {
val field1 = f1._2.withPrefix(f1._1).withPrefix(key)
@@ -17,22 +120,29 @@ case class ObjectMapping2[R, A1, A2](apply: Function2[A1, A2, R], unapply: Funct
case Left(errors) => Left(errors)
case Right(values) => {
applyConstraints(apply(
-
values(0).asInstanceOf[A1],
- values(1).asInstanceOf[A2]))
+ values(1).asInstanceOf[A2]
+ ))
}
}
}
- def unbind(value: R): (Map[String, String], Seq[FormError]) = {
+ def unbind(value: R): Map[String, String] = {
+ unapply(value).map { fields =>
+ val (v1, v2) = fields
+ field1.unbind(v1) ++ field2.unbind(v2)
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
unapply(value).map { fields =>
val (v1, v2) = fields
- val a1 = field1.unbind(v1)
- val a2 = field2.unbind(v2)
+ val a1 = field1.unbindAndValidate(v1)
+ val a2 = field2.unbindAndValidate(v2)
(a1._1 ++ a2._1) ->
(a1._2 ++ a2._2)
- }.getOrElse(Map.empty -> Seq(FormError(key, "unbind.failed")))
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
}
def withPrefix(prefix: String): ObjectMapping2[R, A1, A2] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
@@ -58,24 +168,31 @@ case class ObjectMapping3[R, A1, A2, A3](apply: Function3[A1, A2, A3, R], unappl
case Left(errors) => Left(errors)
case Right(values) => {
applyConstraints(apply(
-
values(0).asInstanceOf[A1],
values(1).asInstanceOf[A2],
- values(2).asInstanceOf[A3]))
+ values(2).asInstanceOf[A3]
+ ))
}
}
}
- def unbind(value: R): (Map[String, String], Seq[FormError]) = {
+ def unbind(value: R): Map[String, String] = {
+ unapply(value).map { fields =>
+ val (v1, v2, v3) = fields
+ field1.unbind(v1) ++ field2.unbind(v2) ++ field3.unbind(v3)
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
unapply(value).map { fields =>
val (v1, v2, v3) = fields
- val a1 = field1.unbind(v1)
- val a2 = field2.unbind(v2)
- val a3 = field3.unbind(v3)
+ val a1 = field1.unbindAndValidate(v1)
+ val a2 = field2.unbindAndValidate(v2)
+ val a3 = field3.unbindAndValidate(v3)
(a1._1 ++ a2._1 ++ a3._1) ->
(a1._2 ++ a2._2 ++ a3._2)
- }.getOrElse(Map.empty -> Seq(FormError(key, "unbind.failed")))
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
}
def withPrefix(prefix: String): ObjectMapping3[R, A1, A2, A3] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
@@ -103,26 +220,33 @@ case class ObjectMapping4[R, A1, A2, A3, A4](apply: Function4[A1, A2, A3, A4, R]
case Left(errors) => Left(errors)
case Right(values) => {
applyConstraints(apply(
-
values(0).asInstanceOf[A1],
values(1).asInstanceOf[A2],
values(2).asInstanceOf[A3],
- values(3).asInstanceOf[A4]))
+ values(3).asInstanceOf[A4]
+ ))
}
}
}
- def unbind(value: R): (Map[String, String], Seq[FormError]) = {
+ def unbind(value: R): Map[String, String] = {
+ unapply(value).map { fields =>
+ val (v1, v2, v3, v4) = fields
+ field1.unbind(v1) ++ field2.unbind(v2) ++ field3.unbind(v3) ++ field4.unbind(v4)
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
unapply(value).map { fields =>
val (v1, v2, v3, v4) = fields
- val a1 = field1.unbind(v1)
- val a2 = field2.unbind(v2)
- val a3 = field3.unbind(v3)
- val a4 = field4.unbind(v4)
+ val a1 = field1.unbindAndValidate(v1)
+ val a2 = field2.unbindAndValidate(v2)
+ val a3 = field3.unbindAndValidate(v3)
+ val a4 = field4.unbindAndValidate(v4)
(a1._1 ++ a2._1 ++ a3._1 ++ a4._1) ->
(a1._2 ++ a2._2 ++ a3._2 ++ a4._2)
- }.getOrElse(Map.empty -> Seq(FormError(key, "unbind.failed")))
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
}
def withPrefix(prefix: String): ObjectMapping4[R, A1, A2, A3, A4] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
@@ -152,28 +276,35 @@ case class ObjectMapping5[R, A1, A2, A3, A4, A5](apply: Function5[A1, A2, A3, A4
case Left(errors) => Left(errors)
case Right(values) => {
applyConstraints(apply(
-
values(0).asInstanceOf[A1],
values(1).asInstanceOf[A2],
values(2).asInstanceOf[A3],
values(3).asInstanceOf[A4],
- values(4).asInstanceOf[A5]))
+ values(4).asInstanceOf[A5]
+ ))
}
}
}
- def unbind(value: R): (Map[String, String], Seq[FormError]) = {
+ def unbind(value: R): Map[String, String] = {
unapply(value).map { fields =>
val (v1, v2, v3, v4, v5) = fields
- val a1 = field1.unbind(v1)
- val a2 = field2.unbind(v2)
- val a3 = field3.unbind(v3)
- val a4 = field4.unbind(v4)
- val a5 = field5.unbind(v5)
+ field1.unbind(v1) ++ field2.unbind(v2) ++ field3.unbind(v3) ++ field4.unbind(v4) ++ field5.unbind(v5)
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
+ unapply(value).map { fields =>
+ val (v1, v2, v3, v4, v5) = fields
+ val a1 = field1.unbindAndValidate(v1)
+ val a2 = field2.unbindAndValidate(v2)
+ val a3 = field3.unbindAndValidate(v3)
+ val a4 = field4.unbindAndValidate(v4)
+ val a5 = field5.unbindAndValidate(v5)
(a1._1 ++ a2._1 ++ a3._1 ++ a4._1 ++ a5._1) ->
(a1._2 ++ a2._2 ++ a3._2 ++ a4._2 ++ a5._2)
- }.getOrElse(Map.empty -> Seq(FormError(key, "unbind.failed")))
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
}
def withPrefix(prefix: String): ObjectMapping5[R, A1, A2, A3, A4, A5] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
@@ -205,30 +336,37 @@ case class ObjectMapping6[R, A1, A2, A3, A4, A5, A6](apply: Function6[A1, A2, A3
case Left(errors) => Left(errors)
case Right(values) => {
applyConstraints(apply(
-
values(0).asInstanceOf[A1],
values(1).asInstanceOf[A2],
values(2).asInstanceOf[A3],
values(3).asInstanceOf[A4],
values(4).asInstanceOf[A5],
- values(5).asInstanceOf[A6]))
+ values(5).asInstanceOf[A6]
+ ))
}
}
}
- def unbind(value: R): (Map[String, String], Seq[FormError]) = {
+ def unbind(value: R): Map[String, String] = {
+ unapply(value).map { fields =>
+ val (v1, v2, v3, v4, v5, v6) = fields
+ field1.unbind(v1) ++ field2.unbind(v2) ++ field3.unbind(v3) ++ field4.unbind(v4) ++ field5.unbind(v5) ++ field6.unbind(v6)
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
unapply(value).map { fields =>
val (v1, v2, v3, v4, v5, v6) = fields
- val a1 = field1.unbind(v1)
- val a2 = field2.unbind(v2)
- val a3 = field3.unbind(v3)
- val a4 = field4.unbind(v4)
- val a5 = field5.unbind(v5)
- val a6 = field6.unbind(v6)
+ val a1 = field1.unbindAndValidate(v1)
+ val a2 = field2.unbindAndValidate(v2)
+ val a3 = field3.unbindAndValidate(v3)
+ val a4 = field4.unbindAndValidate(v4)
+ val a5 = field5.unbindAndValidate(v5)
+ val a6 = field6.unbindAndValidate(v6)
(a1._1 ++ a2._1 ++ a3._1 ++ a4._1 ++ a5._1 ++ a6._1) ->
(a1._2 ++ a2._2 ++ a3._2 ++ a4._2 ++ a5._2 ++ a6._2)
- }.getOrElse(Map.empty -> Seq(FormError(key, "unbind.failed")))
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
}
def withPrefix(prefix: String): ObjectMapping6[R, A1, A2, A3, A4, A5, A6] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
@@ -262,32 +400,39 @@ case class ObjectMapping7[R, A1, A2, A3, A4, A5, A6, A7](apply: Function7[A1, A2
case Left(errors) => Left(errors)
case Right(values) => {
applyConstraints(apply(
-
values(0).asInstanceOf[A1],
values(1).asInstanceOf[A2],
values(2).asInstanceOf[A3],
values(3).asInstanceOf[A4],
values(4).asInstanceOf[A5],
values(5).asInstanceOf[A6],
- values(6).asInstanceOf[A7]))
+ values(6).asInstanceOf[A7]
+ ))
}
}
}
- def unbind(value: R): (Map[String, String], Seq[FormError]) = {
+ def unbind(value: R): Map[String, String] = {
unapply(value).map { fields =>
val (v1, v2, v3, v4, v5, v6, v7) = fields
- val a1 = field1.unbind(v1)
- val a2 = field2.unbind(v2)
- val a3 = field3.unbind(v3)
- val a4 = field4.unbind(v4)
- val a5 = field5.unbind(v5)
- val a6 = field6.unbind(v6)
- val a7 = field7.unbind(v7)
+ field1.unbind(v1) ++ field2.unbind(v2) ++ field3.unbind(v3) ++ field4.unbind(v4) ++ field5.unbind(v5) ++ field6.unbind(v6) ++ field7.unbind(v7)
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
+ unapply(value).map { fields =>
+ val (v1, v2, v3, v4, v5, v6, v7) = fields
+ val a1 = field1.unbindAndValidate(v1)
+ val a2 = field2.unbindAndValidate(v2)
+ val a3 = field3.unbindAndValidate(v3)
+ val a4 = field4.unbindAndValidate(v4)
+ val a5 = field5.unbindAndValidate(v5)
+ val a6 = field6.unbindAndValidate(v6)
+ val a7 = field7.unbindAndValidate(v7)
(a1._1 ++ a2._1 ++ a3._1 ++ a4._1 ++ a5._1 ++ a6._1 ++ a7._1) ->
(a1._2 ++ a2._2 ++ a3._2 ++ a4._2 ++ a5._2 ++ a6._2 ++ a7._2)
- }.getOrElse(Map.empty -> Seq(FormError(key, "unbind.failed")))
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
}
def withPrefix(prefix: String): ObjectMapping7[R, A1, A2, A3, A4, A5, A6, A7] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
@@ -323,34 +468,41 @@ case class ObjectMapping8[R, A1, A2, A3, A4, A5, A6, A7, A8](apply: Function8[A1
case Left(errors) => Left(errors)
case Right(values) => {
applyConstraints(apply(
-
values(0).asInstanceOf[A1],
values(1).asInstanceOf[A2],
values(2).asInstanceOf[A3],
values(3).asInstanceOf[A4],
values(4).asInstanceOf[A5],
values(5).asInstanceOf[A6],
values(6).asInstanceOf[A7],
- values(7).asInstanceOf[A8]))
+ values(7).asInstanceOf[A8]
+ ))
}
}
}
- def unbind(value: R): (Map[String, String], Seq[FormError]) = {
+ def unbind(value: R): Map[String, String] = {
+ unapply(value).map { fields =>
+ val (v1, v2, v3, v4, v5, v6, v7, v8) = fields
+ field1.unbind(v1) ++ field2.unbind(v2) ++ field3.unbind(v3) ++ field4.unbind(v4) ++ field5.unbind(v5) ++ field6.unbind(v6) ++ field7.unbind(v7) ++ field8.unbind(v8)
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
unapply(value).map { fields =>
val (v1, v2, v3, v4, v5, v6, v7, v8) = fields
- val a1 = field1.unbind(v1)
- val a2 = field2.unbind(v2)
- val a3 = field3.unbind(v3)
- val a4 = field4.unbind(v4)
- val a5 = field5.unbind(v5)
- val a6 = field6.unbind(v6)
- val a7 = field7.unbind(v7)
- val a8 = field8.unbind(v8)
+ val a1 = field1.unbindAndValidate(v1)
+ val a2 = field2.unbindAndValidate(v2)
+ val a3 = field3.unbindAndValidate(v3)
+ val a4 = field4.unbindAndValidate(v4)
+ val a5 = field5.unbindAndValidate(v5)
+ val a6 = field6.unbindAndValidate(v6)
+ val a7 = field7.unbindAndValidate(v7)
+ val a8 = field8.unbindAndValidate(v8)
(a1._1 ++ a2._1 ++ a3._1 ++ a4._1 ++ a5._1 ++ a6._1 ++ a7._1 ++ a8._1) ->
(a1._2 ++ a2._2 ++ a3._2 ++ a4._2 ++ a5._2 ++ a6._2 ++ a7._2 ++ a8._2)
- }.getOrElse(Map.empty -> Seq(FormError(key, "unbind.failed")))
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
}
def withPrefix(prefix: String): ObjectMapping8[R, A1, A2, A3, A4, A5, A6, A7, A8] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
@@ -388,7 +540,6 @@ case class ObjectMapping9[R, A1, A2, A3, A4, A5, A6, A7, A8, A9](apply: Function
case Left(errors) => Left(errors)
case Right(values) => {
applyConstraints(apply(
-
values(0).asInstanceOf[A1],
values(1).asInstanceOf[A2],
values(2).asInstanceOf[A3],
@@ -397,27 +548,35 @@ case class ObjectMapping9[R, A1, A2, A3, A4, A5, A6, A7, A8, A9](apply: Function
values(5).asInstanceOf[A6],
values(6).asInstanceOf[A7],
values(7).asInstanceOf[A8],
- values(8).asInstanceOf[A9]))
+ values(8).asInstanceOf[A9]
+ ))
}
}
}
- def unbind(value: R): (Map[String, String], Seq[FormError]) = {
+ def unbind(value: R): Map[String, String] = {
unapply(value).map { fields =>
val (v1, v2, v3, v4, v5, v6, v7, v8, v9) = fields
- val a1 = field1.unbind(v1)
- val a2 = field2.unbind(v2)
- val a3 = field3.unbind(v3)
- val a4 = field4.unbind(v4)
- val a5 = field5.unbind(v5)
- val a6 = field6.unbind(v6)
- val a7 = field7.unbind(v7)
- val a8 = field8.unbind(v8)
- val a9 = field9.unbind(v9)
+ field1.unbind(v1) ++ field2.unbind(v2) ++ field3.unbind(v3) ++ field4.unbind(v4) ++ field5.unbind(v5) ++ field6.unbind(v6) ++ field7.unbind(v7) ++ field8.unbind(v8) ++ field9.unbind(v9)
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
+ unapply(value).map { fields =>
+ val (v1, v2, v3, v4, v5, v6, v7, v8, v9) = fields
+ val a1 = field1.unbindAndValidate(v1)
+ val a2 = field2.unbindAndValidate(v2)
+ val a3 = field3.unbindAndValidate(v3)
+ val a4 = field4.unbindAndValidate(v4)
+ val a5 = field5.unbindAndValidate(v5)
+ val a6 = field6.unbindAndValidate(v6)
+ val a7 = field7.unbindAndValidate(v7)
+ val a8 = field8.unbindAndValidate(v8)
+ val a9 = field9.unbindAndValidate(v9)
(a1._1 ++ a2._1 ++ a3._1 ++ a4._1 ++ a5._1 ++ a6._1 ++ a7._1 ++ a8._1 ++ a9._1) ->
(a1._2 ++ a2._2 ++ a3._2 ++ a4._2 ++ a5._2 ++ a6._2 ++ a7._2 ++ a8._2 ++ a9._2)
- }.getOrElse(Map.empty -> Seq(FormError(key, "unbind.failed")))
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
}
def withPrefix(prefix: String): ObjectMapping9[R, A1, A2, A3, A4, A5, A6, A7, A8, A9] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
@@ -457,7 +616,6 @@ case class ObjectMapping10[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10](apply: Fu
case Left(errors) => Left(errors)
case Right(values) => {
applyConstraints(apply(
-
values(0).asInstanceOf[A1],
values(1).asInstanceOf[A2],
values(2).asInstanceOf[A3],
@@ -467,28 +625,36 @@ case class ObjectMapping10[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10](apply: Fu
values(6).asInstanceOf[A7],
values(7).asInstanceOf[A8],
values(8).asInstanceOf[A9],
- values(9).asInstanceOf[A10]))
+ values(9).asInstanceOf[A10]
+ ))
}
}
}
- def unbind(value: R): (Map[String, String], Seq[FormError]) = {
+ def unbind(value: R): Map[String, String] = {
unapply(value).map { fields =>
val (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) = fields
- val a1 = field1.unbind(v1)
- val a2 = field2.unbind(v2)
- val a3 = field3.unbind(v3)
- val a4 = field4.unbind(v4)
- val a5 = field5.unbind(v5)
- val a6 = field6.unbind(v6)
- val a7 = field7.unbind(v7)
- val a8 = field8.unbind(v8)
- val a9 = field9.unbind(v9)
- val a10 = field10.unbind(v10)
+ field1.unbind(v1) ++ field2.unbind(v2) ++ field3.unbind(v3) ++ field4.unbind(v4) ++ field5.unbind(v5) ++ field6.unbind(v6) ++ field7.unbind(v7) ++ field8.unbind(v8) ++ field9.unbind(v9) ++ field10.unbind(v10)
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
+ unapply(value).map { fields =>
+ val (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) = fields
+ val a1 = field1.unbindAndValidate(v1)
+ val a2 = field2.unbindAndValidate(v2)
+ val a3 = field3.unbindAndValidate(v3)
+ val a4 = field4.unbindAndValidate(v4)
+ val a5 = field5.unbindAndValidate(v5)
+ val a6 = field6.unbindAndValidate(v6)
+ val a7 = field7.unbindAndValidate(v7)
+ val a8 = field8.unbindAndValidate(v8)
+ val a9 = field9.unbindAndValidate(v9)
+ val a10 = field10.unbindAndValidate(v10)
(a1._1 ++ a2._1 ++ a3._1 ++ a4._1 ++ a5._1 ++ a6._1 ++ a7._1 ++ a8._1 ++ a9._1 ++ a10._1) ->
(a1._2 ++ a2._2 ++ a3._2 ++ a4._2 ++ a5._2 ++ a6._2 ++ a7._2 ++ a8._2 ++ a9._2 ++ a10._2)
- }.getOrElse(Map.empty -> Seq(FormError(key, "unbind.failed")))
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
}
def withPrefix(prefix: String): ObjectMapping10[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
@@ -530,7 +696,6 @@ case class ObjectMapping11[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11](appl
case Left(errors) => Left(errors)
case Right(values) => {
applyConstraints(apply(
-
values(0).asInstanceOf[A1],
values(1).asInstanceOf[A2],
values(2).asInstanceOf[A3],
@@ -541,29 +706,37 @@ case class ObjectMapping11[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11](appl
values(7).asInstanceOf[A8],
values(8).asInstanceOf[A9],
values(9).asInstanceOf[A10],
- values(10).asInstanceOf[A11]))
+ values(10).asInstanceOf[A11]
+ ))
}
}
}
- def unbind(value: R): (Map[String, String], Seq[FormError]) = {
+ def unbind(value: R): Map[String, String] = {
+ unapply(value).map { fields =>
+ val (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) = fields
+ field1.unbind(v1) ++ field2.unbind(v2) ++ field3.unbind(v3) ++ field4.unbind(v4) ++ field5.unbind(v5) ++ field6.unbind(v6) ++ field7.unbind(v7) ++ field8.unbind(v8) ++ field9.unbind(v9) ++ field10.unbind(v10) ++ field11.unbind(v11)
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
unapply(value).map { fields =>
val (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) = fields
- val a1 = field1.unbind(v1)
- val a2 = field2.unbind(v2)
- val a3 = field3.unbind(v3)
- val a4 = field4.unbind(v4)
- val a5 = field5.unbind(v5)
- val a6 = field6.unbind(v6)
- val a7 = field7.unbind(v7)
- val a8 = field8.unbind(v8)
- val a9 = field9.unbind(v9)
- val a10 = field10.unbind(v10)
- val a11 = field11.unbind(v11)
+ val a1 = field1.unbindAndValidate(v1)
+ val a2 = field2.unbindAndValidate(v2)
+ val a3 = field3.unbindAndValidate(v3)
+ val a4 = field4.unbindAndValidate(v4)
+ val a5 = field5.unbindAndValidate(v5)
+ val a6 = field6.unbindAndValidate(v6)
+ val a7 = field7.unbindAndValidate(v7)
+ val a8 = field8.unbindAndValidate(v8)
+ val a9 = field9.unbindAndValidate(v9)
+ val a10 = field10.unbindAndValidate(v10)
+ val a11 = field11.unbindAndValidate(v11)
(a1._1 ++ a2._1 ++ a3._1 ++ a4._1 ++ a5._1 ++ a6._1 ++ a7._1 ++ a8._1 ++ a9._1 ++ a10._1 ++ a11._1) ->
(a1._2 ++ a2._2 ++ a3._2 ++ a4._2 ++ a5._2 ++ a6._2 ++ a7._2 ++ a8._2 ++ a9._2 ++ a10._2 ++ a11._2)
- }.getOrElse(Map.empty -> Seq(FormError(key, "unbind.failed")))
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
}
def withPrefix(prefix: String): ObjectMapping11[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
@@ -607,7 +780,6 @@ case class ObjectMapping12[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12]
case Left(errors) => Left(errors)
case Right(values) => {
applyConstraints(apply(
-
values(0).asInstanceOf[A1],
values(1).asInstanceOf[A2],
values(2).asInstanceOf[A3],
@@ -619,30 +791,38 @@ case class ObjectMapping12[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12]
values(8).asInstanceOf[A9],
values(9).asInstanceOf[A10],
values(10).asInstanceOf[A11],
- values(11).asInstanceOf[A12]))
+ values(11).asInstanceOf[A12]
+ ))
}
}
}
- def unbind(value: R): (Map[String, String], Seq[FormError]) = {
+ def unbind(value: R): Map[String, String] = {
+ unapply(value).map { fields =>
+ val (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) = fields
+ field1.unbind(v1) ++ field2.unbind(v2) ++ field3.unbind(v3) ++ field4.unbind(v4) ++ field5.unbind(v5) ++ field6.unbind(v6) ++ field7.unbind(v7) ++ field8.unbind(v8) ++ field9.unbind(v9) ++ field10.unbind(v10) ++ field11.unbind(v11) ++ field12.unbind(v12)
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
unapply(value).map { fields =>
val (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) = fields
- val a1 = field1.unbind(v1)
- val a2 = field2.unbind(v2)
- val a3 = field3.unbind(v3)
- val a4 = field4.unbind(v4)
- val a5 = field5.unbind(v5)
- val a6 = field6.unbind(v6)
- val a7 = field7.unbind(v7)
- val a8 = field8.unbind(v8)
- val a9 = field9.unbind(v9)
- val a10 = field10.unbind(v10)
- val a11 = field11.unbind(v11)
- val a12 = field12.unbind(v12)
+ val a1 = field1.unbindAndValidate(v1)
+ val a2 = field2.unbindAndValidate(v2)
+ val a3 = field3.unbindAndValidate(v3)
+ val a4 = field4.unbindAndValidate(v4)
+ val a5 = field5.unbindAndValidate(v5)
+ val a6 = field6.unbindAndValidate(v6)
+ val a7 = field7.unbindAndValidate(v7)
+ val a8 = field8.unbindAndValidate(v8)
+ val a9 = field9.unbindAndValidate(v9)
+ val a10 = field10.unbindAndValidate(v10)
+ val a11 = field11.unbindAndValidate(v11)
+ val a12 = field12.unbindAndValidate(v12)
(a1._1 ++ a2._1 ++ a3._1 ++ a4._1 ++ a5._1 ++ a6._1 ++ a7._1 ++ a8._1 ++ a9._1 ++ a10._1 ++ a11._1 ++ a12._1) ->
(a1._2 ++ a2._2 ++ a3._2 ++ a4._2 ++ a5._2 ++ a6._2 ++ a7._2 ++ a8._2 ++ a9._2 ++ a10._2 ++ a11._2 ++ a12._2)
- }.getOrElse(Map.empty -> Seq(FormError(key, "unbind.failed")))
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
}
def withPrefix(prefix: String): ObjectMapping12[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
@@ -688,7 +868,6 @@ case class ObjectMapping13[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12,
case Left(errors) => Left(errors)
case Right(values) => {
applyConstraints(apply(
-
values(0).asInstanceOf[A1],
values(1).asInstanceOf[A2],
values(2).asInstanceOf[A3],
@@ -701,31 +880,39 @@ case class ObjectMapping13[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12,
values(9).asInstanceOf[A10],
values(10).asInstanceOf[A11],
values(11).asInstanceOf[A12],
- values(12).asInstanceOf[A13]))
+ values(12).asInstanceOf[A13]
+ ))
}
}
}
- def unbind(value: R): (Map[String, String], Seq[FormError]) = {
+ def unbind(value: R): Map[String, String] = {
+ unapply(value).map { fields =>
+ val (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) = fields
+ field1.unbind(v1) ++ field2.unbind(v2) ++ field3.unbind(v3) ++ field4.unbind(v4) ++ field5.unbind(v5) ++ field6.unbind(v6) ++ field7.unbind(v7) ++ field8.unbind(v8) ++ field9.unbind(v9) ++ field10.unbind(v10) ++ field11.unbind(v11) ++ field12.unbind(v12) ++ field13.unbind(v13)
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
unapply(value).map { fields =>
val (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) = fields
- val a1 = field1.unbind(v1)
- val a2 = field2.unbind(v2)
- val a3 = field3.unbind(v3)
- val a4 = field4.unbind(v4)
- val a5 = field5.unbind(v5)
- val a6 = field6.unbind(v6)
- val a7 = field7.unbind(v7)
- val a8 = field8.unbind(v8)
- val a9 = field9.unbind(v9)
- val a10 = field10.unbind(v10)
- val a11 = field11.unbind(v11)
- val a12 = field12.unbind(v12)
- val a13 = field13.unbind(v13)
+ val a1 = field1.unbindAndValidate(v1)
+ val a2 = field2.unbindAndValidate(v2)
+ val a3 = field3.unbindAndValidate(v3)
+ val a4 = field4.unbindAndValidate(v4)
+ val a5 = field5.unbindAndValidate(v5)
+ val a6 = field6.unbindAndValidate(v6)
+ val a7 = field7.unbindAndValidate(v7)
+ val a8 = field8.unbindAndValidate(v8)
+ val a9 = field9.unbindAndValidate(v9)
+ val a10 = field10.unbindAndValidate(v10)
+ val a11 = field11.unbindAndValidate(v11)
+ val a12 = field12.unbindAndValidate(v12)
+ val a13 = field13.unbindAndValidate(v13)
(a1._1 ++ a2._1 ++ a3._1 ++ a4._1 ++ a5._1 ++ a6._1 ++ a7._1 ++ a8._1 ++ a9._1 ++ a10._1 ++ a11._1 ++ a12._1 ++ a13._1) ->
(a1._2 ++ a2._2 ++ a3._2 ++ a4._2 ++ a5._2 ++ a6._2 ++ a7._2 ++ a8._2 ++ a9._2 ++ a10._2 ++ a11._2 ++ a12._2 ++ a13._2)
- }.getOrElse(Map.empty -> Seq(FormError(key, "unbind.failed")))
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
}
def withPrefix(prefix: String): ObjectMapping13[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
@@ -773,7 +960,6 @@ case class ObjectMapping14[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12,
case Left(errors) => Left(errors)
case Right(values) => {
applyConstraints(apply(
-
values(0).asInstanceOf[A1],
values(1).asInstanceOf[A2],
values(2).asInstanceOf[A3],
@@ -787,32 +973,40 @@ case class ObjectMapping14[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12,
values(10).asInstanceOf[A11],
values(11).asInstanceOf[A12],
values(12).asInstanceOf[A13],
- values(13).asInstanceOf[A14]))
+ values(13).asInstanceOf[A14]
+ ))
}
}
}
- def unbind(value: R): (Map[String, String], Seq[FormError]) = {
+ def unbind(value: R): Map[String, String] = {
unapply(value).map { fields =>
val (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) = fields
- val a1 = field1.unbind(v1)
- val a2 = field2.unbind(v2)
- val a3 = field3.unbind(v3)
- val a4 = field4.unbind(v4)
- val a5 = field5.unbind(v5)
- val a6 = field6.unbind(v6)
- val a7 = field7.unbind(v7)
- val a8 = field8.unbind(v8)
- val a9 = field9.unbind(v9)
- val a10 = field10.unbind(v10)
- val a11 = field11.unbind(v11)
- val a12 = field12.unbind(v12)
- val a13 = field13.unbind(v13)
- val a14 = field14.unbind(v14)
+ field1.unbind(v1) ++ field2.unbind(v2) ++ field3.unbind(v3) ++ field4.unbind(v4) ++ field5.unbind(v5) ++ field6.unbind(v6) ++ field7.unbind(v7) ++ field8.unbind(v8) ++ field9.unbind(v9) ++ field10.unbind(v10) ++ field11.unbind(v11) ++ field12.unbind(v12) ++ field13.unbind(v13) ++ field14.unbind(v14)
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
+ unapply(value).map { fields =>
+ val (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) = fields
+ val a1 = field1.unbindAndValidate(v1)
+ val a2 = field2.unbindAndValidate(v2)
+ val a3 = field3.unbindAndValidate(v3)
+ val a4 = field4.unbindAndValidate(v4)
+ val a5 = field5.unbindAndValidate(v5)
+ val a6 = field6.unbindAndValidate(v6)
+ val a7 = field7.unbindAndValidate(v7)
+ val a8 = field8.unbindAndValidate(v8)
+ val a9 = field9.unbindAndValidate(v9)
+ val a10 = field10.unbindAndValidate(v10)
+ val a11 = field11.unbindAndValidate(v11)
+ val a12 = field12.unbindAndValidate(v12)
+ val a13 = field13.unbindAndValidate(v13)
+ val a14 = field14.unbindAndValidate(v14)
(a1._1 ++ a2._1 ++ a3._1 ++ a4._1 ++ a5._1 ++ a6._1 ++ a7._1 ++ a8._1 ++ a9._1 ++ a10._1 ++ a11._1 ++ a12._1 ++ a13._1 ++ a14._1) ->
(a1._2 ++ a2._2 ++ a3._2 ++ a4._2 ++ a5._2 ++ a6._2 ++ a7._2 ++ a8._2 ++ a9._2 ++ a10._2 ++ a11._2 ++ a12._2 ++ a13._2 ++ a14._2)
- }.getOrElse(Map.empty -> Seq(FormError(key, "unbind.failed")))
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
}
def withPrefix(prefix: String): ObjectMapping14[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
@@ -862,7 +1056,6 @@ case class ObjectMapping15[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12,
case Left(errors) => Left(errors)
case Right(values) => {
applyConstraints(apply(
-
values(0).asInstanceOf[A1],
values(1).asInstanceOf[A2],
values(2).asInstanceOf[A3],
@@ -877,33 +1070,41 @@ case class ObjectMapping15[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12,
values(11).asInstanceOf[A12],
values(12).asInstanceOf[A13],
values(13).asInstanceOf[A14],
- values(14).asInstanceOf[A15]))
+ values(14).asInstanceOf[A15]
+ ))
}
}
}
- def unbind(value: R): (Map[String, String], Seq[FormError]) = {
+ def unbind(value: R): Map[String, String] = {
+ unapply(value).map { fields =>
+ val (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) = fields
+ field1.unbind(v1) ++ field2.unbind(v2) ++ field3.unbind(v3) ++ field4.unbind(v4) ++ field5.unbind(v5) ++ field6.unbind(v6) ++ field7.unbind(v7) ++ field8.unbind(v8) ++ field9.unbind(v9) ++ field10.unbind(v10) ++ field11.unbind(v11) ++ field12.unbind(v12) ++ field13.unbind(v13) ++ field14.unbind(v14) ++ field15.unbind(v15)
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
unapply(value).map { fields =>
val (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) = fields
- val a1 = field1.unbind(v1)
- val a2 = field2.unbind(v2)
- val a3 = field3.unbind(v3)
- val a4 = field4.unbind(v4)
- val a5 = field5.unbind(v5)
- val a6 = field6.unbind(v6)
- val a7 = field7.unbind(v7)
- val a8 = field8.unbind(v8)
- val a9 = field9.unbind(v9)
- val a10 = field10.unbind(v10)
- val a11 = field11.unbind(v11)
- val a12 = field12.unbind(v12)
- val a13 = field13.unbind(v13)
- val a14 = field14.unbind(v14)
- val a15 = field15.unbind(v15)
+ val a1 = field1.unbindAndValidate(v1)
+ val a2 = field2.unbindAndValidate(v2)
+ val a3 = field3.unbindAndValidate(v3)
+ val a4 = field4.unbindAndValidate(v4)
+ val a5 = field5.unbindAndValidate(v5)
+ val a6 = field6.unbindAndValidate(v6)
+ val a7 = field7.unbindAndValidate(v7)
+ val a8 = field8.unbindAndValidate(v8)
+ val a9 = field9.unbindAndValidate(v9)
+ val a10 = field10.unbindAndValidate(v10)
+ val a11 = field11.unbindAndValidate(v11)
+ val a12 = field12.unbindAndValidate(v12)
+ val a13 = field13.unbindAndValidate(v13)
+ val a14 = field14.unbindAndValidate(v14)
+ val a15 = field15.unbindAndValidate(v15)
(a1._1 ++ a2._1 ++ a3._1 ++ a4._1 ++ a5._1 ++ a6._1 ++ a7._1 ++ a8._1 ++ a9._1 ++ a10._1 ++ a11._1 ++ a12._1 ++ a13._1 ++ a14._1 ++ a15._1) ->
(a1._2 ++ a2._2 ++ a3._2 ++ a4._2 ++ a5._2 ++ a6._2 ++ a7._2 ++ a8._2 ++ a9._2 ++ a10._2 ++ a11._2 ++ a12._2 ++ a13._2 ++ a14._2 ++ a15._2)
- }.getOrElse(Map.empty -> Seq(FormError(key, "unbind.failed")))
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
}
def withPrefix(prefix: String): ObjectMapping15[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
@@ -955,7 +1156,6 @@ case class ObjectMapping16[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12,
case Left(errors) => Left(errors)
case Right(values) => {
applyConstraints(apply(
-
values(0).asInstanceOf[A1],
values(1).asInstanceOf[A2],
values(2).asInstanceOf[A3],
@@ -971,34 +1171,42 @@ case class ObjectMapping16[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12,
values(12).asInstanceOf[A13],
values(13).asInstanceOf[A14],
values(14).asInstanceOf[A15],
- values(15).asInstanceOf[A16]))
+ values(15).asInstanceOf[A16]
+ ))
}
}
}
- def unbind(value: R): (Map[String, String], Seq[FormError]) = {
+ def unbind(value: R): Map[String, String] = {
unapply(value).map { fields =>
val (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) = fields
- val a1 = field1.unbind(v1)
- val a2 = field2.unbind(v2)
- val a3 = field3.unbind(v3)
- val a4 = field4.unbind(v4)
- val a5 = field5.unbind(v5)
- val a6 = field6.unbind(v6)
- val a7 = field7.unbind(v7)
- val a8 = field8.unbind(v8)
- val a9 = field9.unbind(v9)
- val a10 = field10.unbind(v10)
- val a11 = field11.unbind(v11)
- val a12 = field12.unbind(v12)
- val a13 = field13.unbind(v13)
- val a14 = field14.unbind(v14)
- val a15 = field15.unbind(v15)
- val a16 = field16.unbind(v16)
+ field1.unbind(v1) ++ field2.unbind(v2) ++ field3.unbind(v3) ++ field4.unbind(v4) ++ field5.unbind(v5) ++ field6.unbind(v6) ++ field7.unbind(v7) ++ field8.unbind(v8) ++ field9.unbind(v9) ++ field10.unbind(v10) ++ field11.unbind(v11) ++ field12.unbind(v12) ++ field13.unbind(v13) ++ field14.unbind(v14) ++ field15.unbind(v15) ++ field16.unbind(v16)
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
+ unapply(value).map { fields =>
+ val (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) = fields
+ val a1 = field1.unbindAndValidate(v1)
+ val a2 = field2.unbindAndValidate(v2)
+ val a3 = field3.unbindAndValidate(v3)
+ val a4 = field4.unbindAndValidate(v4)
+ val a5 = field5.unbindAndValidate(v5)
+ val a6 = field6.unbindAndValidate(v6)
+ val a7 = field7.unbindAndValidate(v7)
+ val a8 = field8.unbindAndValidate(v8)
+ val a9 = field9.unbindAndValidate(v9)
+ val a10 = field10.unbindAndValidate(v10)
+ val a11 = field11.unbindAndValidate(v11)
+ val a12 = field12.unbindAndValidate(v12)
+ val a13 = field13.unbindAndValidate(v13)
+ val a14 = field14.unbindAndValidate(v14)
+ val a15 = field15.unbindAndValidate(v15)
+ val a16 = field16.unbindAndValidate(v16)
(a1._1 ++ a2._1 ++ a3._1 ++ a4._1 ++ a5._1 ++ a6._1 ++ a7._1 ++ a8._1 ++ a9._1 ++ a10._1 ++ a11._1 ++ a12._1 ++ a13._1 ++ a14._1 ++ a15._1 ++ a16._1) ->
(a1._2 ++ a2._2 ++ a3._2 ++ a4._2 ++ a5._2 ++ a6._2 ++ a7._2 ++ a8._2 ++ a9._2 ++ a10._2 ++ a11._2 ++ a12._2 ++ a13._2 ++ a14._2 ++ a15._2 ++ a16._2)
- }.getOrElse(Map.empty -> Seq(FormError(key, "unbind.failed")))
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
}
def withPrefix(prefix: String): ObjectMapping16[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
@@ -1052,7 +1260,6 @@ case class ObjectMapping17[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12,
case Left(errors) => Left(errors)
case Right(values) => {
applyConstraints(apply(
-
values(0).asInstanceOf[A1],
values(1).asInstanceOf[A2],
values(2).asInstanceOf[A3],
@@ -1069,35 +1276,43 @@ case class ObjectMapping17[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12,
values(13).asInstanceOf[A14],
values(14).asInstanceOf[A15],
values(15).asInstanceOf[A16],
- values(16).asInstanceOf[A17]))
+ values(16).asInstanceOf[A17]
+ ))
}
}
}
- def unbind(value: R): (Map[String, String], Seq[FormError]) = {
+ def unbind(value: R): Map[String, String] = {
+ unapply(value).map { fields =>
+ val (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) = fields
+ field1.unbind(v1) ++ field2.unbind(v2) ++ field3.unbind(v3) ++ field4.unbind(v4) ++ field5.unbind(v5) ++ field6.unbind(v6) ++ field7.unbind(v7) ++ field8.unbind(v8) ++ field9.unbind(v9) ++ field10.unbind(v10) ++ field11.unbind(v11) ++ field12.unbind(v12) ++ field13.unbind(v13) ++ field14.unbind(v14) ++ field15.unbind(v15) ++ field16.unbind(v16) ++ field17.unbind(v17)
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
unapply(value).map { fields =>
val (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) = fields
- val a1 = field1.unbind(v1)
- val a2 = field2.unbind(v2)
- val a3 = field3.unbind(v3)
- val a4 = field4.unbind(v4)
- val a5 = field5.unbind(v5)
- val a6 = field6.unbind(v6)
- val a7 = field7.unbind(v7)
- val a8 = field8.unbind(v8)
- val a9 = field9.unbind(v9)
- val a10 = field10.unbind(v10)
- val a11 = field11.unbind(v11)
- val a12 = field12.unbind(v12)
- val a13 = field13.unbind(v13)
- val a14 = field14.unbind(v14)
- val a15 = field15.unbind(v15)
- val a16 = field16.unbind(v16)
- val a17 = field17.unbind(v17)
+ val a1 = field1.unbindAndValidate(v1)
+ val a2 = field2.unbindAndValidate(v2)
+ val a3 = field3.unbindAndValidate(v3)
+ val a4 = field4.unbindAndValidate(v4)
+ val a5 = field5.unbindAndValidate(v5)
+ val a6 = field6.unbindAndValidate(v6)
+ val a7 = field7.unbindAndValidate(v7)
+ val a8 = field8.unbindAndValidate(v8)
+ val a9 = field9.unbindAndValidate(v9)
+ val a10 = field10.unbindAndValidate(v10)
+ val a11 = field11.unbindAndValidate(v11)
+ val a12 = field12.unbindAndValidate(v12)
+ val a13 = field13.unbindAndValidate(v13)
+ val a14 = field14.unbindAndValidate(v14)
+ val a15 = field15.unbindAndValidate(v15)
+ val a16 = field16.unbindAndValidate(v16)
+ val a17 = field17.unbindAndValidate(v17)
(a1._1 ++ a2._1 ++ a3._1 ++ a4._1 ++ a5._1 ++ a6._1 ++ a7._1 ++ a8._1 ++ a9._1 ++ a10._1 ++ a11._1 ++ a12._1 ++ a13._1 ++ a14._1 ++ a15._1 ++ a16._1 ++ a17._1) ->
(a1._2 ++ a2._2 ++ a3._2 ++ a4._2 ++ a5._2 ++ a6._2 ++ a7._2 ++ a8._2 ++ a9._2 ++ a10._2 ++ a11._2 ++ a12._2 ++ a13._2 ++ a14._2 ++ a15._2 ++ a16._2 ++ a17._2)
- }.getOrElse(Map.empty -> Seq(FormError(key, "unbind.failed")))
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
}
def withPrefix(prefix: String): ObjectMapping17[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
@@ -1153,7 +1368,6 @@ case class ObjectMapping18[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12,
case Left(errors) => Left(errors)
case Right(values) => {
applyConstraints(apply(
-
values(0).asInstanceOf[A1],
values(1).asInstanceOf[A2],
values(2).asInstanceOf[A3],
@@ -1171,36 +1385,44 @@ case class ObjectMapping18[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12,
values(14).asInstanceOf[A15],
values(15).asInstanceOf[A16],
values(16).asInstanceOf[A17],
- values(17).asInstanceOf[A18]))
+ values(17).asInstanceOf[A18]
+ ))
}
}
}
- def unbind(value: R): (Map[String, String], Seq[FormError]) = {
+ def unbind(value: R): Map[String, String] = {
unapply(value).map { fields =>
val (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) = fields
- val a1 = field1.unbind(v1)
- val a2 = field2.unbind(v2)
- val a3 = field3.unbind(v3)
- val a4 = field4.unbind(v4)
- val a5 = field5.unbind(v5)
- val a6 = field6.unbind(v6)
- val a7 = field7.unbind(v7)
- val a8 = field8.unbind(v8)
- val a9 = field9.unbind(v9)
- val a10 = field10.unbind(v10)
- val a11 = field11.unbind(v11)
- val a12 = field12.unbind(v12)
- val a13 = field13.unbind(v13)
- val a14 = field14.unbind(v14)
- val a15 = field15.unbind(v15)
- val a16 = field16.unbind(v16)
- val a17 = field17.unbind(v17)
- val a18 = field18.unbind(v18)
+ field1.unbind(v1) ++ field2.unbind(v2) ++ field3.unbind(v3) ++ field4.unbind(v4) ++ field5.unbind(v5) ++ field6.unbind(v6) ++ field7.unbind(v7) ++ field8.unbind(v8) ++ field9.unbind(v9) ++ field10.unbind(v10) ++ field11.unbind(v11) ++ field12.unbind(v12) ++ field13.unbind(v13) ++ field14.unbind(v14) ++ field15.unbind(v15) ++ field16.unbind(v16) ++ field17.unbind(v17) ++ field18.unbind(v18)
+ }.getOrElse(Map.empty)
+ }
+
+ def unbindAndValidate(value: R): (Map[String, String], Seq[FormError]) = {
+ unapply(value).map { fields =>
+ val (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) = fields
+ val a1 = field1.unbindAndValidate(v1)
+ val a2 = field2.unbindAndValidate(v2)
+ val a3 = field3.unbindAndValidate(v3)
+ val a4 = field4.unbindAndValidate(v4)
+ val a5 = field5.unbindAndValidate(v5)
+ val a6 = field6.unbindAndValidate(v6)
+ val a7 = field7.unbindAndValidate(v7)
+ val a8 = field8.unbindAndValidate(v8)
+ val a9 = field9.unbindAndValidate(v9)
+ val a10 = field10.unbindAndValidate(v10)
+ val a11 = field11.unbindAndValidate(v11)
+ val a12 = field12.unbindAndValidate(v12)
+ val a13 = field13.unbindAndValidate(v13)
+ val a14 = field14.unbindAndValidate(v14)
+ val a15 = field15.unbindAndValidate(v15)
+ val a16 = field16.unbindAndValidate(v16)
+ val a17 = field17.unbindAndValidate(v17)
+ val a18 = field18.unbindAndValidate(v18)
(a1._1 ++ a2._1 ++ a3._1 ++ a4._1 ++ a5._1 ++ a6._1 ++ a7._1 ++ a8._1 ++ a9._1 ++ a10._1 ++ a11._1 ++ a12._1 ++ a13._1 ++ a14._1 ++ a15._1 ++ a16._1 ++ a17._1 ++ a18._1) ->
(a1._2 ++ a2._2 ++ a3._2 ++ a4._2 ++ a5._2 ++ a6._2 ++ a7._2 ++ a8._2 ++ a9._2 ++ a10._2 ++ a11._2 ++ a12._2 ++ a13._2 ++ a14._2 ++ a15._2 ++ a16._2 ++ a17._2 ++ a18._2)
- }.getOrElse(Map.empty -> Seq(FormError(key, "unbind.failed")))
+ }.getOrElse(Map.empty[String, String] -> Seq(FormError(key, "unbind.failed")))
}
def withPrefix(prefix: String): ObjectMapping18[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18] = addPrefix(prefix).map(newKey => this.copy(key = newKey)).getOrElse(this)
@@ -1212,4 +1434,3 @@ case class ObjectMapping18[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12,
val mappings = Seq(this) ++ field1.mappings ++ field2.mappings ++ field3.mappings ++ field4.mappings ++ field5.mappings ++ field6.mappings ++ field7.mappings ++ field8.mappings ++ field9.mappings ++ field10.mappings ++ field11.mappings ++ field12.mappings ++ field13.mappings ++ field14.mappings ++ field15.mappings ++ field16.mappings ++ field17.mappings ++ field18.mappings
}
-
View
11 framework/src/play/src/test/scala/play/api/data/FormSpec.scala
@@ -86,6 +86,16 @@ object FormSpec extends Specification {
val f4 = ScalaForms.longNumberForm.fillAndValidate(42);
f3.errors.size must equalTo(0)
}
+
+ "not even attempt to validate on fill" in {
+ val failingValidatorForm = Form(
+ "foo" -> Forms.text.verifying("isEmpty", s =>
+ if (s.isEmpty) true
+ else throw new AssertionError("Validation was run when it wasn't meant to")
+ )
+ )
+ failingValidatorForm.fill("foo").errors must beEmpty
+ }
}
"render form using field[Type] syntax" in {
@@ -142,7 +152,6 @@ object FormSpec extends Specification {
case error => error.message must equalTo("some.error")
}
}
-
}
object ScalaForms {

0 comments on commit 3bebfa7

Please sign in to comment.
Something went wrong with that request. Please try again.