scala - Autofilling a form using the Play Framework -
i have form contains values. when posted server, server validates information, , if of fields invalid, supposed return filled form.
the way have set this.
i have form validates 2 fields.
val userform = form( mapping( "name" -> text, "age" -> number(min=0, max=100) )(user.apply)(user.unapply) )
if form fails bind, load same form values posted.
def createitem() = isauthenticated { username => implicit request => { createexperienceform.bindfromrequest().fold( formwitherrors => badrequest( views.html.createitem(formwitherrors) ), validform => { val itemcode = item.createitem(validform) redirect(routes.item.item(itemcode).url) } ) } }
the problem have manually set value in html page each form. eg. @(itemform: form[itemcontent])
<input name="age" type="number" class="input-block-level" value="@itemform.data.get("age")">
while works, become bit error prone on larger forms. every single field, need set value directly. possible autofill these fields?
the documentation says http://www.playframework.com/documentation/2.2.x/scalaforms - scroll down "fill values"
val userform = userform.fill(user("bob", 18))
Comments
Post a Comment