Fetching contributors…
Cannot retrieve contributors at this time
36 lines (22 sloc) 1.03 KB

Backend: form with meta

In some cases you will find it useful to send some payload with the form that you should be able to extract before processing the form with object.

One good example is sending an entity id of the object backing the form, so that on each POST you will be able to pull it from the database and apply changes that came from the frontend.

Add meta on form creation

When creating the form use the withMeta syntax:

case class Person(id: String, name: String)

val personForm = form[Person](f => List(


which will add the needed payload to the form.

Extract the meta on form posts

The meta can be later extracted on POST calls with:

val id = personForm.getMeta(jsonBody)("id")
val person = personDao.lookup(id)

where jsonBody is the serialized object that comes from the frontend.