A form field.
A form field.
the field name
the constraints associated with the field
the format expected for this field
the errors associated to this field
the field value, if any
A mapping for a single field.
A mapping for a single field.
the field key
the constraints associated with this field.
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) )
the type managed by this form
the form mapping, which describes all form fields
the current form data, used to display the form
the collection of errors associated with this form
a concrete value of type T
if the form submission was successful
A form error.
A form error.
The error key (should be associated with a field using the same key).
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.
Arguments used to format the message.
A mapping is a two-way binder to handle a form field.
Common helper methods for all object mappings - mappings including several fields.
A mapping for optional elements
A mapping for optional elements
the wrapped mapping
A mapping for repeated elements.
A mapping for repeated elements.
The wrapped mapping
A mapping wrapping another existing mapping with transformation functions.
A mapping wrapping another existing mapping with transformation functions.
Existing wrapped mapping
Transformation function from A to B
Transformation function from B to A
Additional constraints of type B
Provides a set of operations for creating Form
values.
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 ) )
Provides a set of operations related to RepeatedMapping
values.
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).right.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) ) }
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.") }
Contains data manipulation helpers (typically HTTP form handling)