package data

Contains data manipulation helpers (typically HTTP form handling)

import play.api.data._
import play.api.data.Forms._

val taskForm = Form(
  tuple(
    "name" -> text(minLength = 3),
    "dueDate" -> date("yyyy-MM-dd"),
    "done" -> boolean
  )
)
Source
package.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. data
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Package Members

  1. package format

    Contains the Format API used by Form.

    Contains the Format API used by Form.

    For example, to define a custom formatter:

    val signedIntFormat = new Formatter[Int] {
    
      def bind(key: String, data: Map[String, String]) = {
        stringFormat.bind(key, data).flatMap { value =>
          scala.util.control.Exception.allCatch[Int]
            .either(java.lang.Integer.parseInt(value))
            .left.map(e => Seq(FormError(key, "error.signedNumber", Nil)))
        }
      }
    
      def unbind(key: String, value: Long) = Map(
        key -> ((if (value<0) "-" else "+") + value)
      )
    }
  2. package validation

    Contains the validation API used by Form.

    Contains the validation API used by Form.

    For example, to define a custom constraint:

    val negative = Constraint[Int] {
      case i if i < 0 => Valid
      case _ => Invalid("Must be a negative number.")
    }

Type Members

  1. class DefaultFormBinding extends FormBinding
  2. case class Field(form: Form[_], name: String, constraints: Seq[(String, Seq[Any])], format: Option[(String, Seq[Any])], errors: Seq[FormError], value: Option[String]) extends Product with Serializable

    A form field.

    A form field.

    name

    the field name

    constraints

    the constraints associated with the field

    format

    the format expected for this field

    errors

    the errors associated to this field

    value

    the field value, if any

  3. case class FieldMapping[T](key: String = "", constraints: Seq[Constraint[T]] = Nil)(implicit binder: Formatter[T]) extends Mapping[T] with Product with Serializable

    A mapping for a single field.

    A mapping for a single field.

    key

    the field key

    constraints

    the constraints associated with this field.

  4. case class Form[T](mapping: Mapping[T], data: Map[String, String], errors: Seq[FormError], value: Option[T]) extends Product with Serializable

    Helper to manage HTML form description, submission and validation.

    Helper to manage HTML form description, submission and validation.

    For example, a form handling a User case class submission:

    import play.api.data._
    import play.api.data.Forms._
    import play.api.data.format.Formats._
    
    val userForm = Form(
      mapping(
        "name" -> of[String],
        "age" -> of[Int],
        "email" -> of[String]
      )(User.apply)(User.unapply)
    )
    T

    the type managed by this form

    mapping

    the form mapping, which describes all form fields

    data

    the current form data, used to display the form

    errors

    the collection of errors associated with this form

    value

    a concrete value of type T if the form submission was successful

  5. trait FormBinding extends AnyRef
  6. case class FormError(key: String, messages: Seq[String], args: Seq[Any] = Nil) extends Product with Serializable

    A form error.

    A form error.

    key

    The error key (should be associated with a field using the same key).

    messages

    The form message (often a simple message key needing to be translated), if more than one message is passed the last one will be used.

    args

    Arguments used to format the message.

  7. case class FormJsonExpansionTooDeep(limit: Int) extends RuntimeException with NoStackTrace with Product with Serializable
  8. case class FormJsonExpansionTooLarge(limit: Long) extends RuntimeException with NoStackTrace with Product with Serializable
  9. trait Mapping[T] extends AnyRef

    A mapping is a two-way binder to handle a form field.

  10. trait ObjectMapping extends AnyRef

    Common helper methods for all object mappings - mappings including several fields.

  11. class ObjectMapping1[R, A1] extends Mapping[R] with ObjectMapping
  12. class ObjectMapping10[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10] extends Mapping[R] with ObjectMapping
  13. class ObjectMapping11[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11] extends Mapping[R] with ObjectMapping
  14. class ObjectMapping12[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12] extends Mapping[R] with ObjectMapping
  15. class ObjectMapping13[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13] extends Mapping[R] with ObjectMapping
  16. class ObjectMapping14[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14] extends Mapping[R] with ObjectMapping
  17. class ObjectMapping15[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15] extends Mapping[R] with ObjectMapping
  18. class ObjectMapping16[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16] extends Mapping[R] with ObjectMapping
  19. class ObjectMapping17[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17] extends Mapping[R] with ObjectMapping
  20. class ObjectMapping18[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18] extends Mapping[R] with ObjectMapping
  21. class ObjectMapping19[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19] extends Mapping[R] with ObjectMapping
  22. class ObjectMapping2[R, A1, A2] extends Mapping[R] with ObjectMapping
  23. class ObjectMapping20[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20] extends Mapping[R] with ObjectMapping
  24. class ObjectMapping21[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21] extends Mapping[R] with ObjectMapping
  25. class ObjectMapping22[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22] extends Mapping[R] with ObjectMapping
  26. class ObjectMapping3[R, A1, A2, A3] extends Mapping[R] with ObjectMapping
  27. class ObjectMapping4[R, A1, A2, A3, A4] extends Mapping[R] with ObjectMapping
  28. class ObjectMapping5[R, A1, A2, A3, A4, A5] extends Mapping[R] with ObjectMapping
  29. class ObjectMapping6[R, A1, A2, A3, A4, A5, A6] extends Mapping[R] with ObjectMapping
  30. class ObjectMapping7[R, A1, A2, A3, A4, A5, A6, A7] extends Mapping[R] with ObjectMapping
  31. class ObjectMapping8[R, A1, A2, A3, A4, A5, A6, A7, A8] extends Mapping[R] with ObjectMapping
  32. class ObjectMapping9[R, A1, A2, A3, A4, A5, A6, A7, A8, A9] extends Mapping[R] with ObjectMapping
  33. case class OptionalMapping[T](wrapped: Mapping[T], constraints: Seq[Constraint[Option[T]]] = Nil) extends Mapping[Option[T]] with Product with Serializable

    A mapping for optional elements

    A mapping for optional elements

    wrapped

    the wrapped mapping

  34. case class RepeatedMapping[T](wrapped: Mapping[T], key: String = "", constraints: Seq[Constraint[List[T]]] = Nil) extends Mapping[List[T]] with Product with Serializable

    A mapping for repeated elements.

    A mapping for repeated elements.

    wrapped

    The wrapped mapping

  35. case class WrappedMapping[A, B](wrapped: Mapping[A], f1: (A) => B, f2: (B) => A, additionalConstraints: Seq[Constraint[B]] = Nil) extends Mapping[B] with Product with Serializable

    A mapping wrapping another existing mapping with transformation functions.

    A mapping wrapping another existing mapping with transformation functions.

    wrapped

    Existing wrapped mapping

    f1

    Transformation function from A to B

    f2

    Transformation function from B to A

    additionalConstraints

    Additional constraints of type B

Value Members

  1. object Form extends Serializable

    Provides a set of operations for creating Form values.

  2. object FormBinding
  3. object FormError extends Serializable
  4. object Forms

    Contains data manipulation helpers (typically HTTP form handling)

    Contains data manipulation helpers (typically HTTP form handling)

    import play.api.data._
    import play.api.data.Forms._
    
    val taskForm = Form(
      of(Task.apply _, Task.unapply _)(
        "name" -> text(minLength = 3),
        "dueDate" -> date("yyyy-MM-dd"),
        "done" -> boolean
      )
    )
  5. object JodaForms
  6. object RepeatedMapping extends Serializable

    Provides a set of operations related to RepeatedMapping values.