Skip to content

Commit

Permalink
Fix error showing when field not used
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasfortes committed Dec 18, 2024
1 parent 8938124 commit 54c9634
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/backpex/fields/has_many.ex
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ defmodule Backpex.Fields.HasMany do
</span>
</label>
<input type="hidden" id={"has-many-#{@name}-hidden-input"} name={@form[@name].name} value="" />
<input type="hidden" id={"has-many-#{@name}-hidden-input"} name={"#{@form[@name].name}[]"} value="" />
<input
:for={value <- @selected_ids}
Expand Down Expand Up @@ -336,8 +336,11 @@ defmodule Backpex.Fields.HasMany do
defp get_assocs_by_ids(assoc_ids, schema, repo, field_options, assigns) do
case assoc_ids do
ids when is_list(ids) and ids != [] ->

filtered_ids = Enum.reject(ids, &(&1 == ""))

schema
|> where([x], x.id in ^ids)
|> where([x], x.id in ^filtered_ids)
|> maybe_options_query(field_options, assigns)
|> repo.all()

Expand Down

0 comments on commit 54c9634

Please sign in to comment.