hx-include
include field values in request
<input type="text" id="username" placeholder="Enter your name"><select id="language"> <option value="English">English</option> <option value="Spanish">Spanish</option> <!-- other options --></select><button hx-post="/submit-data" hx-trigger="click" hx-include="#username, #language">Submit</button>hx-trigger
trigger GET request, on change of Select option
<select id="options"> <option value="option1">Option 1</option> <option value="option2">Option 2</option> <!-- other options --></select>trigger values
click
hx-vals
add JSON value to request
<div id="bq">Some Data</div><button type="button" class="btn btn-primary btn-sm" type="submit" value="Submit"or
hx-vals='{"somekey": "somevalue"}'passing a Jinja variable to the API backend
<button type="button" class="btn btn-info" id="email_btn" data-bs-toggle="modal" data-bs-target="#basemodal" data-bs-title="Email Applicants" data-bs-modalsize="modal-lg" hx-get="{% url 'mm_email_applicants' %}" hx-target="#modal-body-area" hx-vals='{"search_data": "{{search_data}}"}'>update multiple elements with a single backend request
index.html
<div id="test1">Joe</div><div>some long content here</div><button hx-get="/backend" hx-swap="innerHTML" hx-select-oob="#test1">Update</button>backend.py
return HttpResponse("""will render test1 to Fred, and update text of button
to render more than 2 swaps via 1 API call, use extension
https://github.com/bigskysoftware/htmx-extensions/blob/main/src/multi-swap/README.md
CSS Properties
change CSS property
<div class="row" id="row_1">some row text</div><input type="checkbox" _="on click set row_1.style['background-color'] to 'red'"></input>or via human-language
<button _="on click set #row_1's *background-color to 'red'"> Set It's Background To Red</button>multiple ON events
<input class="form-check-input" name="checkbox" type="checkbox" id="mycheckbox" {% if checkbox %}checked{% endif %} _="on load or click if my.checked is true show #someField else hide #someFieldget HTML element by custom attribute and do stuff to element with same ID number (get ID based on form, update TR with same row_ID
<form class="form" id="modal-conn-form" conn_id="12">get all checkbox elements that are checked on, skip anything with ID="select_all_chk" and append all selected "conn_id" attributes to an array
example data
<input id="row_{{row.id}}" conn_id={{row.id}}>
<input id="row_{{row.id}}" conn_id={{row.id}}>
<input id="row_{{row.id}}" conn_id={{row.id}}>
get list of all Conn_IDs, for each ID, make a POST request to backend 'delete' route