-
Notifications
You must be signed in to change notification settings - Fork 22
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
How to fill in inputs_for #133
Comments
Hmmm. That's interesting. That may be a case we missed. @andrewtimberlake if you try the same thing but have the labels and inputs separated, does it work? I think it might have to do wih the implicit label <> input association (which we should handle) In other words, does it work if it's like this? <div>
<label for="model_0_name">Name:</label> <input name="model[0][name]" id="model_0_name" />
</div>
<div>
<label for="model_1_name">Name:</label> <input name="model[1][name]" id="model_1_name" />
</div> |
They are actually separate. I’m using the |
That sounds like a bug in that case -- but it's weird because that's exactly what our tests are testing. I wonder if there's something odd with Can you confirm you're using v0.4.0, and is there a chance you could create a simple app that reproduces the error? |
I have created a simple app that demonstrates what I’m trying to do: |
@andrewtimberlake thanks for the repo! Made it much easier to figure out. Your test in that repo has two errors:
So, all in all, your test should look like this: test "add items", %{conn: conn} do
conn
|> visit("/test")
|> assert_has("h1", text: "PhoenixTestInputsFor")
|> check("add more")
|> fill_in("[name='model[items][0][name]']", "Name", with: "Item 1")
|> check("add more")
|> fill_in("[name='model[items][1][name]']", "Name", with: "Item 2")
|> check("add more")
|> fill_in("[name='model[items][2][name]']", "Name", with: "Item 3")
|> submit()
end Here's the diff: |> visit("/test")
|> assert_has("h1", text: "PhoenixTestInputsFor")
|> check("add more")
- |> fill_in("model[items][0][name]", with: "Item 1")
+ |> fill_in("[name='model[items][0][name]']", "Name", with: "Item 1")
|> check("add more")
- |> fill_in("model[items][1][name]", with: "Item 2")
+ |> fill_in("[name='model[items][1][name]']", "Name", with: "Item 2")
|> check("add more")
- |> fill_in("model[items][2][name]", with: "Item 3")
+ |> fill_in("[name='model[items][2][name]']", "Name", with: "Item 3")
|> submit()
end When I run ☝️ that, the test passes. Hope that helps! |
Thanks for the help. <button type="button" name="model[items][]" value="new" phx-click={JS.dispatch("change")}>
add more
</button> |
@andrewtimberlake any chance you could create a simple app (or modify the one you already shared) to reproduce the error you're running into? |
I’m not sure if there’s a better place to ask questions.
When using inputs_for for a multiple inputs where each iteration is still an open form, how do you target each input with
fill_in
?Example html:
The text was updated successfully, but these errors were encountered: