Inside of a modal window I'm loading a form template via jQuery .load
. For reasons I don't know, the {% js %}
tags that need to come with the form template are not being loaded, even though the {% js %}
tag is placed at the bottom of the loaded partial.
Here's the loading code
{% js %}
MicroModal.init()
$(document).ready(function() {
$('.trigger').click(function() {
event.preventDefault();
MicroModal.show('addressModal');
$('.c-modal__content').load('account/profile/billing/add #newAddressForm');
});
});
{% endjs %}
On click a modal will open, retrieve the template, look for the #newAddressForm
ID element, and an address form template will load within it. The HTML part of the form loads fine, but no JS is brought with it.
The loaded partial template:
<form method="post" id="newAddressForm">
<input type="hidden" name="action" value="commerce/customer-addresses/save">
{{ csrfInput() }}
{% include "shop/_inc/addresses/form" %}
<button type="submit">Save</button>
</form>
And lastly, the {% include %}
has the form fields and {% js %}
tag inside.
To reiterate, the HTML of the form loads fine. The JS does not come with it. I'm not sure if this is an issue with Twig, Craft, or jQuery. Help would be appreciated!