Hi,
I was trying to refactor my few forms (modal integrated forms) into a “form factory template”, and thus decided to make an html file that I include with arguments to set up the form -such as next, action, form…-
The call is working fine, but I’d like to keep my previous behaviour : when the form is not valid and I get it back with errors, open the modal right away (after document loaded). Currently i can’t do so, I suppose it’s because when I wait for document load event, it’s for the main html page, and it doesn’t wait for django included html files. Thus, I need to pass my js file to my form factory so it can wait for the modal creation before calling “show”.
The issue is my js file has a dynamic base directory I normally fetch like this (and it’s working). And i obviously don’t want to change this behaviour :
<script src="{% static 'vendor/libs/datatables-bs5/datatables.js' %}"></script>
I saw that I cant use template tags inside template tags and thus cannot call
{% include "partials/modals/django_form_factory.html" with modalId="equipmentCreationModal" ... js_path={% static '.../my_js.js' %}
I saw that I can make temporary variables through template tags but that wouldn’t work as i need to compute the variable through template tags.
I finally found about {% static as %} and tried it :
{% static 'org/js/equipments/create_equipment.js' as js_path %}
But this doesn’t work, {{ js_path }} evaluate to “static/org/js/equipments/create_equipment.js”.
Is there a way to feed files paths to {% includes %} other than this one or am I doing something stupid there ?
On a side note, i couldn’t find doc on a point : breaking lines inside very long templates for code readability. Here I have many arguments in my {% include %} and thus the lines are way too long to be readable. Didn’t try escaping '' the end of lines yet as i was focused on the previous problem (and left my code as is, being a bit burnt by it)
Exemple of line :
{% include "partials/modals/django_form_factory.html" with modalId="equipmentCreationModal" action=url_equipment_creation modalTitle="Create Equipment" form=form submit_text="Add Equipment" cancel_button_style="secondary" submit_button_style="success" js_path=js_path next_url="" %}
Thanks a lot for the help !