Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to post a collection of ids with multiple select form field with phoenix_html

I’m trying to get multiple select to work with the phoenix_html form helpers

<%= select f, :challenge_ids, ["foo": "1","bar": "2","baz": "3"], class: "form-control", multiple: ""  %>

but only the id of the last selected item gets sent to the server in the params

%{"challenge_ids" => "3", "content" => "", "name" => ""}

I have also tried changing :challeng_ids to :"challenge_ids[]" trying to get something similar to a rails output for a multiple select tag, but this didn't make any difference

like image 423
Aaron Dufall Avatar asked Jul 12 '15 23:07

Aaron Dufall


1 Answers

Aaron's PR for adding multiple_select was merged into phoenix_html. Here's an example from the docs for multiple_select/4 in case someone else stumbled across the same problem:

# Assuming form contains a User model
multiple_select(form, :roles, ["Admin": 1, "Power User": 2])
#=> <select id="user_roles" name="user[roles][]">
    <option value="1">Admin</option>
    <option value="2">Power User</option>
    </select>
like image 66
Nithin Avatar answered Nov 12 '22 10:11

Nithin