Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play! Framework with scala - Form seq(text) binding

I'm trying to bind a seq of text to a scala Form. What I have so far is the following code:

val registerForm = Form[User](
mapping(
  "login" -> text,
  "password" -> text,
  "roles" -> seq(text)
) {
  (login, password, roles) => User(login = login, password = password, roles = roles)
} {
  user => Some((user.login, user.password, user.roles))
})

My HTML form select is:

<select id="roles" name="roles"  multiple="multiple">
    <option value="ADMIN">Admin</option>
    <option value="TESTER">Tester</option>
</select>

Login and password are binded correctly. My problem is that the seq of roles is always empty.

I've checked in the request object passed to the controller method and (if selected) both roles are there - they are just not binded correctly in form object.

Any ideas?

Edit:

I also posted my question at play-framework Google Group (https://groups.google.com/forum/#!topic/play-framework/KcbiF9K3d8w) and received answer there. The solution is to give select a name: "roles[]" instead of "roles".

like image 838
lgasior Avatar asked Oct 12 '13 10:10

lgasior


1 Answers

Figured it out.

The solution is to give select a name: "roles[]" instead of "roles".

like image 140
lgasior Avatar answered Sep 30 '22 10:09

lgasior