I am trying to use htmx inside django-formtools and I have problem getting the consistent id and name of the form in the partial HTML as in the main HTML. A little bit of explanation, in the main HTML of the formtool all the form field rendered will get additional prefix of the name of the step of the wizard for the id and name of the field, for example if your step is listing and your field name is category, the rendered field id will be "id_listing-category" instead of "id_category" and the name will be "listing-category" instead of "category". I am using render field of widget_tweaks to render the field. The problem is when I render the field in the partial HTML using render_field the id and name of the form field have no prefix of the step as in the formfield generated in the main HTML. I suspect this is caused by the unavailability of wizard object in the partial HTML. I can print the wizard object in the main HTML but get blank when I try to print in the partial HTML. To solve this problem I have tried two things:
- Pass the wizard object to the partial HTML using HTMX hx-include and hx-vals but I get an error and no wizard object is being passed.
- I have tried to template inheritance using django-template-partials using {% partialdef inline-partial inline=True %} but with no success. I still can get the wizard object inside the partial.
- Use combination of Alpine JS and HTMX. I tried to show or hide the fields using Alpine JS based on the select option value and at the same time generated the option value of cascaded select using HTMX. I have not been succesful yet using this method.
If somehow I can get access of the wizard object inside the partial then all the above problems should be solved instead of making unnecessary work around. Any comment or input on how to achieve this is much appreciated. Am I missing something or I guess I just have to make my own formtools.