# Handling Multiple Dynamic Forms (HTMX vs inline formsets + JavaScript vs multiple forms on one site)

**URL:** <https://forum.djangoproject.com/t/handling-multiple-dynamic-forms-htmx-vs-inline-formsets-javascript-vs-multiple-forms-on-one-site/33332>\
**Category:** Forms & APIs\
**Created:** [July 27, 2024, 9:34am UTC](https://forum.djangoproject.com/t/handling-multiple-dynamic-forms-htmx-vs-inline-formsets-javascript-vs-multiple-forms-on-one-site/33332 "2024-07-27T09:34:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suhel-El-Salim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/suhel-el-salim/32/22862_2.png) [@Suhel-El-Salim](https://forum.djangoproject.com/u/Suhel-El-Salim)\
**Post date:** [July 27, 2024, 9:34am UTC](https://forum.djangoproject.com/t/handling-multiple-dynamic-forms-htmx-vs-inline-formsets-javascript-vs-multiple-forms-on-one-site/33332/1 "2024-07-27T09:34:39Z")

</div>

Hello @all,

I like to code a form where user optional can upload an undefined number of files. The User exists already in the database and has to complete data in that form + upload optional files. There are two Models (User(1):Files(n)).

What I like to discuss is, what is best practice in this case, because there are different options available (inline formsets + JavaScript, HTMX, multiple forms with one submit, etc)

What I have done so far is to work with inline formsets and JavaScript. The user selects a file and when he want’s to add another file, another formsnippet is added via JavaScript. What I don’t like about this approach, is the handling of renaming all formsnippets when a form is dynamically removed (not the last form).

What is your approach to handle this challange? Does anyone has solved this with htmx?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 27, 2024, 11:08am UTC](https://forum.djangoproject.com/t/handling-multiple-dynamic-forms-htmx-vs-inline-formsets-javascript-vs-multiple-forms-on-one-site/33332/2 "2024-07-27T11:08:42Z")

</div>

Welcome @Suhel-El-Salim !

This is a case where someone has entered a form and decides to remove it before submitting it? Or is this a case where they’re bringing up a form that already has entries from a previous submission?

In general, in either case, you do not need to physically delete the form from the formset. If you set the `can_delete` attribute on the formset, you can logically delete the forms without needing to rename subsequent forms.

See the docs at [Formsets | Django documentation | Django](https://docs.djangoproject.com/en/5.0/topics/forms/formsets/#dealing-with-ordering-and-deletion-of-forms) for further details.

---

<div class="post-metadata">

**Author:** ![Suhel-El-Salim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/suhel-el-salim/32/22862_2.png) [@Suhel-El-Salim](https://forum.djangoproject.com/u/Suhel-El-Salim)\
**Post date:** [July 27, 2024, 11:32am UTC](https://forum.djangoproject.com/t/handling-multiple-dynamic-forms-htmx-vs-inline-formsets-javascript-vs-multiple-forms-on-one-site/33332/3 "2024-07-27T11:32:26Z")

</div>

Hello Ken,

thank you for your support, I have read already a lot of your answers to questions in this forum 🙂

This is a general question how to handle this aproach. Not only technical, but also from user perspective.

If a user want’s to add another file for upload and presses the ‘Add’ Button, instantly a new formfield appears. The user now would expect that if he presses a delete button, that the uploadfield (formfield) and the content instantly dissapears. A checkbox to mark a formfield for deletion would be inconsistently. Also I can’t trust that the user always deletes only the last field.

My question is, what is technical and from a user perspective a good approach to solve this problem and how are solving other users this challange. HTMX seems to be a solution that can fit.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 27, 2024, 4:31pm UTC](https://forum.djangoproject.com/t/handling-multiple-dynamic-forms-htmx-vs-inline-formsets-javascript-vs-multiple-forms-on-one-site/33332/4 "2024-07-27T16:31:37Z")

</div>

With a delete, you do not _need_ to show it as a checkbox. You can render a trashcan icon that sets the delete flag and hides the div. But the form itself remains as part of the formset. It’s a lot easier that way. (That’s how we handle it.)

---

<div class="post-metadata">

**Author:** ![Suhel-El-Salim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/suhel-el-salim/32/22862_2.png) [@Suhel-El-Salim](https://forum.djangoproject.com/u/Suhel-El-Salim)\
**Post date:** [July 27, 2024, 5:26pm UTC](https://forum.djangoproject.com/t/handling-multiple-dynamic-forms-htmx-vs-inline-formsets-javascript-vs-multiple-forms-on-one-site/33332/5 "2024-07-27T17:26:08Z")

</div>

That’s a smart solution, and so easy… 😀

Do you have further experience with Django multiple/dynamic forms and HTMX? With regard to the potential of HTMX as JavaScript alternative, what is your opinon, if I may ask?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 28, 2024, 7:35pm UTC](https://forum.djangoproject.com/t/handling-multiple-dynamic-forms-htmx-vs-inline-formsets-javascript-vs-multiple-forms-on-one-site/33332/6 "2024-07-28T19:35:30Z")

</div>

Using formsets with HTMX? Not much. (I do have a project where the “add another form” function is an AJAX request handled by HTMX, but that’s about it.)

But I do a _lot_ of work with dynamic forms (forms created or modified by views), and I’m _absolutely_ a huge fan of HTMX.

I won’t say that HTMX replaces or eliminates JavaScript for me, but it has greatly reduced the amount of JavaScript I need to write. (I think _some_ of what I do _could_ be handled by either HTMX or Alpine, but I’m ok with the mix I have.)
