Forum: Ruby on Rails Select multiple question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F28f75d17a0c236e079c6ebbb8fff2b9?d=identicon&s=25 Mark Haliday (markh)
on 2006-01-13 19:47
I've got the following code in my view:

<select name="user[member_list][]" multiple="multiple">

<%= options_from_collection_for_select @someUsers, "id", "username" %>

</select>

I have a few other fields, textboxes, etc. within the form.  When I go
to save the info, the textboxes all save with their content, but the
select box doesn't -- it displays values in it, no problem.  When I
print the contents of the params[:user] I see all the fields in the form
along with their values except the Multi Select -- its nowhere to be
found.  I've tried naming it: user[member_list][] as well as:
user[member_list]

Neither works.
F28f75d17a0c236e079c6ebbb8fff2b9?d=identicon&s=25 Mark Haliday (markh)
on 2006-01-13 22:45
Upon further investigation I've found out that you have to have the
items in the multiselect highlighted in order to have them save.  This
is problematic for me because I have two multiselects and I shuffle
usernames between the two (user management).  I don't want to have to
have the one multiselect highlight the choosen values for saving.  Isn't
there a way just to save anything in a multiselect?
4005a47a8f2ceee49670b920593c1d52?d=identicon&s=25 Ben Munat (Guest)
on 2006-01-14 21:01
(Received via mailing list)
Write a javascript function that gets the select element and loops
through the option
children, setting each selected. Hook that up to the form's onsubmit.

Or, maybe someone's done something in rails to make this for you...

b
This topic is locked and can not be replied to.