Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to populate a dropdown using the html helper "options" in a scala template (play 2.0)

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!

like image 851
techbheegaran Avatar asked Dec 05 '22 17:12

techbheegaran


1 Answers

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.

like image 166
huynhjl Avatar answered Jun 01 '23 05:06

huynhjl