Hi!
I’m not very good at English, I supported the post with a translator. Sorry for that.
I think it’s something that’s been discussed before, but I’m not being able to find a solution, or a nice way to do it.
I am working with Django and HTMX. I have a View to manage records on two models, plus two forms with an inlineformset.
In the form, there are several parts that I render dynamically with HTMX. It depends on what the user selects in the select, I render other selects that by default I load empty. When the user change some values, the correspond values is render with HTMX functions.
The problem is that when you want to submit, the form is not complete. I can’t validate the form because it doesn’t contain the information I loaded dynamically with HTMX.
At this point I’m trying different approaches.
- The HTMX view returns an HTML that is rendered by a dictionary with the dynamic values.
At this point the problem is that the form is not aware of the available values, nor of course the selected value.
To validate it, i try modifying the queryset with the values from the post in the view, manually. It generates multiple problems, in addition to not being able to render a form with the selected values in case of a server-side error.
- The HTMX view returns an HTML that is rendered by a form.
At this point I need to pass the values already selected in the GET to the HTMX view, so I can create the complete form and replace it in the DOM. I think it can work, but I don’t like the idea.
So, what do you recommend I do, research or read?
If you think some code can help, I can add something. But I don’t want to make too much noise, I understand that it must be something super resolved with some pattern or something that I’m overlooking.
Thank you so much!