HTMX + Django: Modern Python Web Apps, Hold the JavaScript Transcripts
Chapter: Feature 1: Click-to-edit
Lecture: Inserting the cancel button
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Now it's time to add the cancel button to the form. Let me open the form up. Not much new here, just a button in the form.
0:13
BTN Danger is a style thing, it just makes the button red. And as I hinted before, swapping out the form means an HX Get attribute,
0:25
this time to a new view that responds with the Click to Edit link instead. On the Click to Edit link, I used HXSwap. This time I'm using HXTarget.
0:40
The HXTarget attribute takes a CSS selector, which in this case points at the form tag. HXSwap is used to change the tag it's associated with,
0:50
While HXTarget allows you to change anything you can identify on the page.
0:55
Say I wanted a button that changed the footer, but the button wasn't in the footer, HXTarget would be how you did that.
1:03
That's it for the HTML. Now all I need to do is add the new view for the link.