Skip to content

Commit

Permalink
Merge pull request #25 from dwyl/assigns
Browse files Browse the repository at this point in the history
displays changeset from assigns correctly
  • Loading branch information
nelsonic authored Nov 7, 2018
2 parents 6af4815 + 7741e84 commit a01b9a9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/autoform.ex
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,13 @@ defmodule Autoform do
Phoenix.View.render(
Autoform.CustomView,
"custom.html",
%{
Keyword.get(options, :assigns, %{})
|> Map.new()
|> Map.put_new(:changeset, first_schema.changeset(struct(first_schema), %{}))
|> Map.merge(%{
elements: element_assigns,
changeset: first_schema.changeset(struct(first_schema), %{}),
action: Keyword.get(options, :path, path(conn, action, first_schema, options))
}
})
)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/templates/custom/custom.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
id="<%=element.schema_name%>_<%=assoc[:name]%>_<%=String.split(Map.get(a, :display)) |> Enum.join |> Macro.underscore()%>"
name="<%=element.schema_name%>[<%=assoc[:name]%>][<%=String.to_atom(Map.get(a, :display))%>]"
class="form-control"
<%= if Map.get(assoc.loaded_associations, assoc[:name]) |> Enum.find(fn l -> Map.get(l, :name) == Map.get(a, :display) || Map.get(l, :type) == Map.get(a, :display) end) do "checked" end%>
<%= if (Map.get(assoc.loaded_associations, assoc[:name]) || []) |> Enum.find(fn l -> Map.get(l, :name) == Map.get(a, :display) || Map.get(l, :type) == Map.get(a, :display) end) do "checked" end%>
>
<label for="<%=element.schema_name%>_<%=assoc[:name]%>_<%=String.to_atom(Map.get(a, :display))%>"><%= Map.get(a, :display) |> String.capitalize() %></label>
<% end %>
Expand Down

0 comments on commit a01b9a9

Please sign in to comment.