I have a Form with a nested list of mappings, but have problems iterating this in the template. The Form looks like this
val assignmentForm : Form[AssignmentData] = Form(
"acceptedSign" -> nonEmptyText(),
mapping("activities" -> list (
mapping("activityId" -> optional(text),
"activityStatus" -> optional(text))
(ActivityData.apply)(ActivityData.unapply))
)(AssignmentData.apply)(AssignmentData.unapply)
)
I am passing this form into the template and try to iterate over the activities. So far only compiler errors or a complete metadata dump of the Form as a result.
This gives a metadata+data dump of the complete form, with the activity included. (the LI tag is a tab navigator that will contain input fields)
@repeat(assignmentForm("activities")) { activity =>
<li>@activity("activityId")</li>
}
Iteration sort of works (is the code runs), but it is completely unusable from a user standpoint.
I have also tried various for-loops, only giving me compiler errors, saying
value map is not a member of play.api.data.Field
My questions are:
The solution is as simple as this, navtab.scala.html
@**
* Generate an LI element
*@
@(field: play.api.data.Field)
<li><a href='#@field.id' data-toggle="modal">@field("activityStatus").value</a></li>
Then repeat for the mapped collection in your template
<ul id="activities">
@repeat(assignmentForm("activities"), min=0) { activity =>
@navtab(activity)
}
</ul>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With