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".