germsvel / phoenix_test

MIT License
150 stars 22 forks source link

How to fill in inputs_for #133

Open andrewtimberlake opened 3 hours ago

andrewtimberlake commented 3 hours ago

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:

<div>
<label>Name: <input name="model[0][name]" id="model_0_name" /></label>
</div>
<div>
<label>Name: <input name="model[1][name]" id="model_1_name" /></label>
</div>
conn |> fill_in("model[0][name]", "Name", with: "John Doe")
** (ArgumentError) Found many labels with text "Name":
germsvel commented 2 hours ago

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>
andrewtimberlake commented 2 hours ago

They are actually separate. I’m using the <.input /> component (my example above was a simplified example using HTML as I tend to write it by hand. The problem is that there are multiple labels with the same name