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

Nested form with hidden inputs raises ArgumentError #117

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
image: elixir:latest

tasks:
- init: mix deps.get && mix compile
command: iex -S mix
14 changes: 14 additions & 0 deletions test/phoenix_test/live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,20 @@ defmodule PhoenixTest.LiveTest do
|> assert_has("#full-form option[value='elf']")
end

test "selects option in a nested form generated by inputs_for", %{conn: conn} do
# ** (ArgumentError) value for hidden "elf[cloak][_touched]" must be one of ["_form_type,_persistent_id,_touched,name,type"], got: "color,type"
# code: |> select("Small", from: "Elf Cloak Size")
# stacktrace:
# (phoenix_live_view 0.20.17) lib/phoenix_live_view/test/live_view_test.ex:1102: Phoenix.LiveViewTest.call/2
# (phoenix_test 0.3.1) lib/phoenix_test/live.ex:219: PhoenixTest.Live.fill_form/3

conn
|> visit("/live/index")
|> fill_in("Elf Cloak Color", with: "Green")
|> select("Small", from: "Elf Cloak Size")
|> assert_has("#nested-form-with-hidden-inputs option[value='small']")
end

test "works in 'nested' forms", %{conn: conn} do
conn
|> visit("/live/index")
Expand Down
17 changes: 17 additions & 0 deletions test/support/index_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ defmodule PhoenixTest.IndexLive do
Save Owner Form
</button>

<form id="nested-form-with-hidden-inputs" phx-submit="save-form" phx-change="validate">
<input type="hidden" name="elf[cloak][_persistent_id]" value="0">
<input type="hidden" name="elf[cloak][_touched]" value="">
<input type="hidden" name="elf[cloak][_form_type]" value="create">
<label for="elf_cloak_color">Elf Cloak Color</label>
<input type="text" name="elf[cloak][color]" id="elf_cloak_color" phx-debounce="300">
<label for="elf_cloak_size">Elf Cloak Size</label>
<select name="elf[cloak][size]" id="elf_cloak_size">
<option value="small">Small</option>
<option value="large">Large</option>
</select>
</form>

<form id="nested-form" phx-submit="save-form">
<label for="user-name">User Name</label>
<input id="user-name" name="user[name]" />
Expand Down Expand Up @@ -343,6 +356,10 @@ defmodule PhoenixTest.IndexLive do
}
end

def handle_event("validate", _form_data, socket) do
{:noreply, socket}
end

def handle_event("save-redirect-form", _, socket) do
{:noreply, push_navigate(socket, to: "/live/page_2")}
end
Expand Down