Skip to content
Open
15 changes: 6 additions & 9 deletions lib/kaffy/resource_form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ defmodule Kaffy.ResourceForm do
end

permission =
case is_nil(changeset.data.id) do
case is_nil(Map.get(changeset.data, :id)) do
true -> Map.get(options, :create, :editable)
false -> Map.get(options, :update, :editable)
end
Expand All @@ -73,11 +73,6 @@ defmodule Kaffy.ResourceForm do
end
end

def form_field(changeset, form, {field, options}, opts) do
type = Kaffy.ResourceSchema.field_type(changeset.data.__struct__, field)
build_html_input(changeset.data, form, {field, options}, type, opts)
end

defp build_html_input(schema, form, {field, options}, type, opts, readonly \\ false) do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aesmail can you double check this chunk of code to see if it affects any logic?

data = schema
{conn, opts} = Keyword.pop(opts, :conn)
Expand All @@ -93,12 +88,14 @@ defmodule Kaffy.ResourceForm do
inputs_for(form, field, fn fp ->
[
{:safe, ~s(<div class="card ml-3" style="padding:15px;">)},
Enum.reduce(embed_fields, [], fn f, all ->
Enum.reduce(embed_fields, [], fn {embed_f, embed_f_options}, all ->
content_tag :div, class: "form-group" do
[
[
form_label(fp, f),
form_field(embed_changeset, fp, {f, options}, class: "form-control")
form_label(fp, embed_f),
form_field(embed_changeset, fp, {embed_f, embed_f_options},
class: "form-control"
)
]
| all
]
Expand Down
3 changes: 2 additions & 1 deletion lib/kaffy/resource_schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ defmodule Kaffy.ResourceSchema do
end

defp reorder_fields(fields_list, schema) do
[_id, first_field | _fields] = schema.__schema__(:fields)
[first_field | _fields] = schema.__schema__(:fields) -- [:id]

# this is a "nice" feature to re-order the default fields to put the specified fields at the top/bottom of the form
fields_list
Expand Down Expand Up @@ -296,6 +296,7 @@ defmodule Kaffy.ResourceSchema do

def field_type(_schema, {_, type}), do: type
def field_type(schema, field), do: schema.__changeset__() |> Map.get(field, :string)

# def field_type(schema, field), do: schema.__schema__(:type, field)

def get_map_fields(schema) do
Expand Down