Skip to content

Commit eac0a0a

Browse files
committed
fix: handle case where last item in add form path is an integer
fixes #211
1 parent 78b3f29 commit eac0a0a

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

lib/ash_phoenix/form/form.ex

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,17 +2684,7 @@ defmodule AshPhoenix.Form do
26842684
def get_form(form, path) do
26852685
form = to_form!(form)
26862686

2687-
path =
2688-
case path do
2689-
[] ->
2690-
[]
2691-
2692-
path when is_list(path) ->
2693-
path
2694-
2695-
path ->
2696-
parse_path!(form, path)
2697-
end
2687+
path = parse_path!(form, path)
26982688

26992689
case path do
27002690
[] ->
@@ -2724,6 +2714,9 @@ defmodule AshPhoenix.Form do
27242714
nil
27252715
end
27262716
end
2717+
rescue
2718+
InvalidPath ->
2719+
nil
27272720
end
27282721

27292722
defp to_form!(%__MODULE__{} = form), do: form
@@ -4643,7 +4636,19 @@ defmodule AshPhoenix.Form do
46434636

46444637
{path, last} =
46454638
if opts[:skip_last?] do
4646-
{:lists.droplast(path), List.last(path)}
4639+
last = List.last(path)
4640+
4641+
if is_binary(last) do
4642+
case Integer.parse(last) do
4643+
{int, ""} ->
4644+
{:lists.droplast(path), int}
4645+
4646+
_ ->
4647+
{:lists.droplast(path), last}
4648+
end
4649+
else
4650+
{:lists.droplast(path), last}
4651+
end
46474652
else
46484653
{path, nil}
46494654
end

0 commit comments

Comments
 (0)