如何使用phoenix_html发布具有多个选择表单字段的ID集合

时间:2015-07-12 23:55:20

标签: elixir phoenix-framework

我正在尝试使用phoenix_html表单助手

进行多项选择
<%= select f, :challenge_ids, ["foo": "1","bar": "2","baz": "3"], class: "form-control", multiple: ""  %>

但只有最后一个选定项目的id才会被发送到params

中的服务器
%{"challenge_ids" => "3", "content" => "", "name" => ""}

我还尝试将:challeng_ids更改为:"challenge_ids[]",试图获得类似于多选标记的rails输出的内容,但这没有任何区别

1 个答案:

答案 0 :(得分:7)

Aaron的PR for adding multiple_select被合并到phoenix_html中。以下是multiple_select/4 # 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> 的示例,以防其他人偶然发现同一问题:

B = {0 1 1 1 1; 0 -1 -1 1 1; 0 1 1 -1 2}
B = 

    [0]    [ 1]    [ 1]    [ 1]    [1]
    [0]    [-1]    [-1]    [ 1]    [1]
    [0]    [ 1]    [ 1]    [-1]    [2]