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".
Figured it out.
The solution is to give select a name: "roles[]" instead of "roles".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With