shahryarjb
if I put this <input type="hidden" name="id" value="<%= item.id %>"> line in lee file LiveView in handle event repeat html tags
but if I change name to sthid, it works as well, I think id name is one of the parameters we shouldn’t use them in our source.
<div class="col-md-3" data-toggle="collapse" data-target="#FoodS" aria-expanded="false" phx-click="show-category-foods" phx-value-category-id="<%= category.id %>">
...
....
.....
......
<div class="spacer20"> </div>
<div class="col-md-11 mx-auto collapse" id="FoodS">
<div class="row">
<%= for item <- @foods do %>
<div class="col-md-3">
<form phx-submit="save-client-food">
<div class="foodbox text-center" data-mh="landing-cards">
<img class="u-mb-small img-fluid" src="<%= item.image %>">
<div class="spacer20"> </div>
<h5 class="u-h6 u-text-bold u-mb-small text-center"><%= item.title %></h5>
</div>
<div class="spacer20"> </div>
<div class="row text-center mx-auto">
<button type="submit" class="btn btn-outline-danger mr-3">انتخاب</button>
<input type="text" class="form-control col-md-6 mr-3" name="number" placeholder="انتخاب"/>
</div>
<input type="hidden" name="foodid" value="<%= item.id %>">
</form>
<div class="spacer20"> </div>
</div>
<% end %>
</div>
</div>
handle_event
def handle_event("show-category-foods", %{"category-id" => category_id}, socket) do
{:noreply, assign(socket, foods: CategoryQuery.show_category_foods(category_id))}
end
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
slouchpie
I do not think this is a LiveView bug.
If the form is re-rendered in any way, it will be duplicated in the HTML, as you say.
But you can see in the devtools console that
does not return a string (like every other HTML element we are used to) but instead returns the child input with name “id”.
I
slouchpie
OK this might actually be a Live View bug. I don’t know.
I have created an example live view which shows weirdness with
name="id"forms and conditionally rendered divs.If you run this and click on “Click Me”, you will see form 1 get duplicated.
The bug goes away if you change
name="id"to, say,name="something-else".slouchpie
This one is weird for the same underlying reason (input with name=“id”) but is immediately obvious on render:
This renders the first 2 forms with duplicates!
karim-semmoud
I think each input must have a unique id, the name can be whatever but the id has to be unique.
You can try this instead
I guess Phoenix, is generating duplicates ids for your name automatically, therefore the duplicate fields with sames ids when rendering, but this is just a guess
By using Phoenix HTML Form build-in .form this behavior is enforced and you receive error message for duplicate ids
Phoenix HTML Form will append the form id to each field, so that the ids are unique even even they are the same field names across multiple forms
You can have multiples forms without ids with different field names, but if you are going to have common field name across forms, then you must add and id to your form.
Phoenix HTML
to_formprovides an option to add the idHere is a working example with multiple forms
Doing the following will not work and will throw duplicate ids error in the console
You can use inspect(@form) you see the difference between a form using the opts id option and one without the form id will be nil
Hope this will help
wanton7
slouchpie
Thanks for sharing this. I did try to find existing conversations about it.