Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assoc number or text input #326

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions lib/kaffy/resource_form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ defmodule Kaffy.ResourceForm do
:id ->
case field in Kaffy.ResourceSchema.primary_keys(schema) do
true -> text_input(form, field, opts)
false -> text_or_assoc(conn, schema, form, field, opts)
false -> text_or_assoc(conn, schema, form, field, type, opts)
end

t when t in [:binary_id, Ecto.ULID] ->
case field in Kaffy.ResourceSchema.primary_keys(schema) do
true -> text_input(form, field, opts)
false -> text_or_assoc(conn, schema, form, field, opts)
false -> text_or_assoc(conn, schema, form, field, type, opts)
end

:string ->
Expand Down Expand Up @@ -351,7 +351,7 @@ defmodule Kaffy.ResourceForm do
end
end

defp text_or_assoc(conn, schema, form, field, opts) do
defp text_or_assoc(conn, schema, form, field, type, opts) do
actual_assoc =
Enum.filter(Kaffy.ResourceSchema.associations(schema), fn a ->
Kaffy.ResourceSchema.association(schema, a).owner_key == field
Expand All @@ -376,12 +376,22 @@ defmodule Kaffy.ResourceForm do

content_tag :div, class: "input-group" do
[
number_input(form, field,
class: "form-control",
id: field,
disabled: opts[:readonly],
aria_describedby: field
),
case type do
:id ->
number_input(form, field,
class: "form-control",
id: field,
disabled: opts[:readonly],
aria_describedby: field
)
_ ->
text_input(form, field,
class: "form-control",
id: field,
disabled: opts[:readonly],
aria_describedby: field
)
end,
if opts[:readonly] do
""
else
Expand Down Expand Up @@ -443,7 +453,12 @@ defmodule Kaffy.ResourceForm do
end

false ->
number_input(form, field, opts)
case type do
:id ->
number_input(form, field, opts)
_ ->
text_input(form, field, opts)
end
end
end

Expand Down
Loading