Hi, I am following instructions from a blog - Many to many associations in Elixir and Phoenix - DEV Community
I am trying to allow a user to choose products from a list using checkoboxes. I am getting this error - (CompileError) undefined function f/0
in my template. What am I doing wrong?
This is my template:
<div class="form-group">
<%=
multiselect_checkboxes(
f,
:foods,
Enum.map(@foods, fn f -> {f.name, f.id} end),
selected: Enum.map(@changeset.data.foods,&(&1.id))
)
%>
</div>
This is my multiselect_checkboxes
function
def multiselect_checkboxes(form, field, options, opts \\ []) do
{selected, _} = get_selected_values(form, field, opts)
selected_as_strings = Enum.map(selected, &"#{&1}")
for {value, key} <- options, into: [] do
content_tag(:label, class: "checkbox-inline") do
[
tag(:input,
name: input_name(form, field) <> "[]",
id: input_id(form, field, key),
type: "checkbox",
value: key,
checked: Enum.member?(selected_as_strings, "#{key}")
),
value
]
end
end
end