Opened 2 months ago

Closed 2 months ago

#35647 closed Bug (invalid)

Templating Engine Auto-Closing Forms

Reported by: Nischal lamichhane Owned by:
Component: Template system Version: 4.2
Severity: Release blocker Keywords: templating engine
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Sarah Boyce)

I was Trying to integrate HTMX into my django application's frontend. and noticed a weird and what seems like a breaking issue.
Following is the html code that I have in my html file being rendered:

<form 
	hx-post="{% url 'batch_delete' pk=batch.id %}"
	hx-trigger="submit"
	hx-target="#batchesListCard"
	hx-swap="innerHTML"
	hx-on::before-request="$(this).closest('.modal').modal(hide)" 
	> 
	 	{% csrf_token %}
		<button
			type="submit"
			class="btn btn-danger mt-3">
				Yes
		</button>
	</form>

Following is what is seen my inspecting Element in my Browser.

<form hx-post="/batches/22/delete/" hx-trigger="submit" hx-target="#batchesListCard" hx-swap="innerHTML" hx-on::before-request="$(this).closest('.modal').modal(hide)"></form>
<input type="hidden" name="csrfmiddlewaretoken" value="csrf_value">
<button type="submit" class="btn btn-danger mt-3">
    Yes
</button>

As you can see, the form is being auto-closed by the templating engine,
The error however isnt in every form, It is happening to the form(with no user input) that is used with htmx to be used as a trigger.

Change History (3)

comment:1 by Nischal lamichhane, 2 months ago

Please contact me if you need more information to reproduce the bug

comment:2 by Sarah Boyce, 2 months ago

Description: modified (diff)

comment:3 by Sarah Boyce, 2 months ago

Resolution: invalid
Status: newclosed

I am pretty sure this is not a Django issue but instead something funky around the htmx swapping of target and innerHTML
If you can confirm there is an issue in Django's template rendering, independent to htmx, please reopen the issue

Note: See TracTickets for help on using tickets.
Back to Top