Sheldon Wei
Sheldon Wei

Reputation: 1252

how to generate option values in Playframework Form helper @select


i want to generate a <select> tag in Play Form. but the option values are not fixed. so i coded it as this:

@select(
    myF("server_id"),
    options(
        for(s <- servers){s.getId -> s.getName}
    )
)

however, the compiler tells out that:

Overloaded method value [apply] cannot be applied to (Unit)

cannot i use for sub in option? and how should i code? thx.

Upvotes: 1

Views: 2282

Answers (1)

James Roper
James Roper

Reputation: 12850

@select takes a sequence of (String, String) tuples. You already have a sequence (servers), so you just to map them to tuples:

@select(
  myF("server_id"),
  servers.map(s => s.getId -> s.getName)
)

Upvotes: 3

Related Questions