adamghill / django-unicorn

The magical reactive component framework for Django ✨
https://www.django-unicorn.com
MIT License
2.37k stars 120 forks source link

Forms do not render correctly for added elements #452

Closed lancernik closed 9 months ago

lancernik commented 2 years ago

At first I would like to say thank you for this framework, it is brilliant and easy to use!

I render the form to each of the objects in the list, but sometimes there are situations where the form does not display properly. After examining an item, you can't even see its source code

Suppose we add an item form for each tag in the todo application. For such an added element, the code contained in form tag completely disappears

`

{% if tasks %}

    {% for task in tasks %}
  • {{ task }}
  • {% endfor %}
{% else %} No tasks 🎉 {% endif %}

`

Bug

VidyaYadavv1519 commented 9 months ago

Ensure that each form has a unique ID. The id attribute in your form should be unique for each form on the page. Having multiple forms with the same ID can lead to rendering issues.

adamghill commented 9 months ago

Sorry @lancernik I definitely missed this issue in the past. Usually this happens because morphdom gets a little confused about which elements should be on the page. I have made a few changes recently that should potentially help with this situation or @VidyaYadavv1519's solution of adding a a unique id will probably help as well! I'm going to close this, but let me know if you still run into problems.