FieldMapping

play.api.data.FieldMapping
case class FieldMapping[T](key: String, constraints: Seq[Constraint[T]])(implicit binder: Formatter[T]) extends Mapping[T]

A mapping for a single field.

Value parameters

constraints

the constraints associated with this field.

key

the field key

Attributes

Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait Mapping[T]
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def as(binder: Formatter[T]): Mapping[T]

Changes the binder used to handle this field.

Changes the binder used to handle this field.

Value parameters

binder

the new binder to use

Attributes

Returns

the same mapping with a new binder

def bind(data: Map[String, String]): Either[Seq[FormError], T]

Binds this field, i.e. constructs a concrete value from submitted data.

Binds this field, i.e. constructs a concrete value from submitted data.

Value parameters

data

the submitted data

Attributes

Returns

either a concrete value of type T or a set of errors, if binding failed

def unbind(value: T): Map[String, String]

Unbinds this field, i.e. transforms a concrete value to plain data.

Unbinds this field, i.e. transforms a concrete value to plain data.

Value parameters

value

the value to unbind

Attributes

Returns

the plain data

Unbinds this field, i.e. transforms a concrete value to plain data, and applies validation.

Unbinds this field, i.e. transforms a concrete value to plain data, and applies validation.

Value parameters

value

the value to unbind

Attributes

Returns

the plain data and any errors in the plain data

def verifying(addConstraints: Constraint[T]*): Mapping[T]

Constructs a new Mapping based on this one, by adding new constraints.

Constructs a new Mapping based on this one, by adding new constraints.

For example:

 import play.api.data._
 import validation.Constraints._

 Form("phonenumber" -> text.verifying(required) )

Value parameters

addConstraints

the constraints to add

Attributes

Returns

the new mapping

def withPrefix(prefix: String): Mapping[T]

Constructs a new Mapping based on this one, adding a prefix to the key.

Constructs a new Mapping based on this one, adding a prefix to the key.

Value parameters

prefix

the prefix to add to the key

Attributes

Returns

the same mapping, with only the key changed

Inherited methods

protected def addPrefix(prefix: String): Option[String]

Attributes

Inherited from:
Mapping
protected def applyConstraints(t: T): Either[Seq[FormError], T]

Attributes

Inherited from:
Mapping
protected def collectErrors(t: T): Seq[FormError]

Attributes

Inherited from:
Mapping

Attributes

Inherited from:
Product

Attributes

Inherited from:
Product
def transform[B](f1: T => B, f2: B => T): Mapping[B]

Transform this Mapping[T] to a Mapping[B].

Transform this Mapping[T] to a Mapping[B].

Type parameters

B

The type of the new mapping.

Value parameters

f1

Transform value of T to a value of B

f2

Transform value of B to a value of T

Attributes

Inherited from:
Mapping
def verifying(error: => String, constraint: T => Boolean): Mapping[T]

Constructs a new Mapping based on this one, by adding a new ad-hoc constraint.

Constructs a new Mapping based on this one, by adding a new ad-hoc constraint.

For example:

 import play.api.data._
 import validation.Constraints._

 Form("phonenumber" -> text.verifying("Bad phone number", {_.grouped(2).size == 5}))

Value parameters

constraint

a function describing the constraint that returns false on failure

error

The error message used if the constraint fails

Attributes

Returns

the new mapping

Inherited from:
Mapping
def verifying(constraint: T => Boolean): Mapping[T]

Constructs a new Mapping based on this one, by adding a new ad-hoc constraint.

Constructs a new Mapping based on this one, by adding a new ad-hoc constraint.

For example:

 import play.api.data._
 import validation.Constraints._

 Form("phonenumber" -> text.verifying {_.grouped(2).size == 5})

Value parameters

constraint

a function describing the constraint that returns false on failure

Attributes

Returns

the new mapping

Inherited from:
Mapping

Concrete fields

override val format: Option[(String, Seq[Any])]

The Format expected for this field, if it exists.

The Format expected for this field, if it exists.

Attributes

val mappings: Seq[Mapping[_]]

Sub-mappings (these can be seen as sub-keys).

Sub-mappings (these can be seen as sub-keys).

Attributes

Implicits

Implicits

implicit val binder: Formatter[T]