Reputation: 73
I'm really a starter with Scala, so pardon me if I'm stupid here!
I'm using play2.0/Scala for an assignment.
I want to populate a dropdown with distinct values(timesheetId here) and labels(a concat of 2 date values). So I did this.
@select(effortForm("timesheetId"),options(timesheets.map(aTimesheet=> aTimesheet.timesheetId.toString -> (aTimesheet.fromDate + " to " + aTimesheet.toDate))),'_label->"Choose Timesheet (*)")
But the page has a dropdown populated with same value (as a tuple) and label for options under select.
Overloaded method value [apply] cannot be applied to (List[(java.lang.String, java.lang.String)])
I want to see this as result
<option value="1">Sun Apr 08 18:23:32 PDT 2012 to Sun Apr 08 18:23:32 PDT 2012</option>
Please help!
Upvotes: 4
Views: 5758
Reputation: 13519
There is an excellent example in the samples/java installation directory that ships with your play installation. See "forms". SignUp - > Countries
Upvotes: 0
Reputation: 41646
Try this:
@select(
effortForm("timesheetId"),
timesheets.map{ t =>
t.timesheetId.toString -> (t.fromDate + " to " + t.toDate)
},
'_label- > "Choose Timesheet (*)"
)
Looking at the implementation of select, it looks like the second parameter should be a Seq[(String, String)]
which would already be the case for your timesheets.map{ }
.
options(...)
provides conveniences methods to constructs the Seq[(String, String)]
and there is not a method that applies here.
Upvotes: 16