Bug: Cannot mark the first checkbox inside a form as checked
pmargreff opened this issue · comments
Context:
I'm trying to use some checkbox and notice that no matter what the first checkbox can never be created as checked
, following a code sample:
<%= form_for @conn, Routes.setup_path(@conn, :things_post), fn _f -> %>
<p>
<label>
<input type="checkbox" name="things[]" value="thing1" checked>
<input type="checkbox" name="things[]" value="thing2" checked>
<input type="checkbox" name="things[]" value="thing3" checked>
</label>
</p>
<%= submit "Submit" %>
<% end %>
However, if you move the inputs out of the form it works as expected. Please, note that I'm using HTML tags, it does not work even with plain and boring HTML.
I'm happy to send you a patch, just need some pointers of what I should be looking for (spent some time but had no progress on identifying the root cause).
Hi @pmargreff , can you please fill in the issues template?
Sorry, I saw now that you submitted this in phoenix_html
and there is no issues template. 😬
Can you please provide more information? Is this within a LiveView? Outside of a LiveView? What Phoenix version?
Np, I'm not using LiveView, versions are:
- phoenix: 1.6.6
- phoenix_html: 3.2.0
As additional context, if I try to use tags like (<%= checkbox(f, :famous, checked: true) %>
) the problem does not happen. Seems like it just occurs when trying to use barebones inputs inside form tags.
Yeah, so I suspect this is not related to Phoenix.HTML. If you define the form by hand, does the issue exist?
Yes, it works, one more thing. I just discovered that the issue is intermittent. After I used the checkbox tag to test it I could never go back to a state where it does not work, 🤔 .
I'll assume I did something wrong and the code that I sent to you was not the problem (which is contradictory because I tested it several times).
Will close the issue and reopen it if it ever happens again.