Skip to content

Commit

Permalink
Merge pull request #33 from dwyl/changeset-fixes
Browse files Browse the repository at this point in the history
Changeset fixes
  • Loading branch information
nelsonic authored Dec 7, 2018
2 parents 9c7a930 + 9f22e45 commit f7b412f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/templates/custom/custom.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<%= if html = Map.get(element, :html) do %>
<%= html %>
<% else %>
<%= if String.to_existing_atom(element.schema_name) in @assoc_list do %>
<%= inputs_for f, :user, fn p -> %>
<%= if assoc_schema = one_of([String.to_existing_atom(element.schema_name), element.schema.__schema__(:source)], @assoc_list) do %>
<%= inputs_for f, assoc_schema, fn p -> %>
<%= render "field_inputs.html", element: element, f: p, changeset: @changeset %>
<% end %>
<% else %>
Expand Down
25 changes: 18 additions & 7 deletions lib/views/custom_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,26 @@ defmodule Autoform.CustomView do

# Apply any sensible defaults here, but we should allow configuration of individual input options
opts =
Keyword.merge(
opts,
[value: form.source.changes[field]] ++
case schema.__schema__(:type, field) do
:float -> [step: 0.01]
_ -> []
end
opts
|> Keyword.merge(
case schema.__schema__(:type, field) do
:float -> [step: 0.01]
_ -> []
end
)
|> Keyword.merge(
cond do
map_size(form.source.changes) > 0 -> [value: form.source.changes[field]]
true -> []
end
)

apply(Phoenix.HTML.Form, type, [form, field, opts])
end

def one_of(list_1, list_2) do
Enum.reduce(list_1, nil, fn el, acc ->
if el in list_2, do: el
end)
end
end

0 comments on commit f7b412f

Please sign in to comment.