mysterious-toddler-20573
02/03/2023, 3:35 AMrich-traffic-81552
02/03/2023, 3:36 AMmysterious-toddler-20573
02/03/2023, 3:36 AMmysterious-toddler-20573
02/03/2023, 3:36 AMmysterious-toddler-20573
02/03/2023, 3:37 AMmysterious-toddler-20573
02/03/2023, 3:37 AMrich-traffic-81552
02/03/2023, 3:38 AMrich-traffic-81552
02/03/2023, 3:38 AMlittle-electrician-91324
02/03/2023, 8:12 AMhtml
<input class="form-control" type="search"
name="search" placeholder="Begin Typing To Search Users..."
hx-post="/search"
hx-trigger="keyup changed delay:500ms, search"
hx-target="#search-results"
hx-indicator=".htmx-indicator">
I want to include more values in the search and @stocky-dentist-80693 helped me yesterday and said that one idea was to wrap this input field in a form. This works well when I click the button, i.e. it includes both the value from search input field as well as the value from the button:
html
<form id="search-form"
hx-post="/search"
hx-target="#search-form"
hx-swap="outerHTML"
hx-trigger="keyup changed delay:500ms from:#search-input, search from:input, submit"
hx-indicator=".htmx-indicator"
hx-include="#search-form">
<input class="form-control" type="search"
name="search" placeholder="Begin Typing To Search Users...">
<button type="submit" name="something" value="hello">Hello</button>
</form>
However, I've now lost the functionality from the search input field, i.e. the form is not submitted on keyup changed delay:500ms
when I place this trigger in the form
instead of the input
element. I've thus tried to add the from:#search-input
event modifier, but this doesn't seem to work for multiple events. If I change hx-trigger
to to hx-trigger="keyup from:#search-input, search from:input, submit"
, then the form is posted, but I loose denouncing etc. How can I make this work?famous-iron-45600
02/03/2023, 2:57 PMHX-Location
header that has path /dashboard
.Then the user hits the browser back btn and gets an empty login form again. At this point, I'd like to redirect him to /dashboard
again because he has a valid session. The session data are stored in a cookie. I couldn't find any good example on what is htmx
approach to handle that kind of situation. Any hints?rich-traffic-81552
02/03/2023, 3:40 PMchanged
modifier on the
keyup changed delay:500ms from:#search-input
trigger checks the value of the element the trigger is defined on, not the target. so it'll get the change event from the input, check the form's value (which doesn't exist) and say it didn't change. If you get rid of changed
i think it should workmysterious-toddler-20573
02/03/2023, 3:40 PMmysterious-toddler-20573
02/03/2023, 3:41 PMhx-history='false'
to it (thank you @hundreds-cartoon-20446 !)orange-umbrella-16693
02/03/2023, 6:36 PMorange-umbrella-16693
02/03/2023, 6:36 PMmysterious-toddler-20573
02/03/2023, 6:37 PMmysterious-toddler-20573
02/03/2023, 6:41 PMpreventDefault()
explicitlymysterious-toddler-20573
02/03/2023, 6:41 PMbumpy-kangaroo-60192
02/03/2023, 8:36 PMorange-umbrella-16693
02/03/2023, 8:44 PM<button hx-get="/data">OK</button>
And change it to
<button hx-get="/data" hx-trigger="myCustomEvent from:body">OK</button>
So that it also fires when some custom event is fired, will it still trigger the GET on click or do I have to add it beside the custom event namemysterious-toddler-20573
02/03/2023, 9:03 PMhx-trigger="click, myCustomEvent from:body"
great-gold-37694
02/04/2023, 3:56 PMripe-action-67367
02/04/2023, 3:57 PMrefined-waiter-90422
02/04/2023, 4:59 PMrefined-waiter-90422
02/04/2023, 4:59 PMgreen-activity-6102
02/04/2023, 6:13 PMhtmx:confirm
event on a post request, is there a way to extract the hx-vals
in the callback? I want to change the confirmation dialog based on what's being postedgreen-activity-6102
02/04/2023, 6:59 PMhtmx:confirm
callback? I've got inputs in my Sweetalert and i want to attach those input values into the requestprehistoric-garden-45720
02/04/2023, 11:10 PMbeforebegin
, afterbegin
, beforeend
and afterend
values for the hx-swap-oob
attribute also result in an inline swap, as is currently the case for the true
and outerHTML
values?
For example, given this HTML page:
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>HTMX Test</title>
<script src="/src/htmx.js"></script>
<script>
htmx.config.useTemplateFragments = true;
</script>
</head>
<body>
<div
id="test"
hx-get="/htmx-test2.html"
hx-trigger="load delay:1s"
hx-swap="outerHTML"
>
<p>Test BEFORE swap</p>
</div>
<hr />
<h2>Contacts</h2>
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th></th>
</tr>
</thead>
<tbody id="contacts-table">
<tr>
<td>Cell 1a</td>
<td>Cell 1b</td>
</tr>
</tbody>
</table>
</body>
</html>
If the content of /htmx-test2.html
is:
html
<tr hx-swap-oob="afterbegin:#contacts-table">
<td>Joe Smith</td>
<td>joe@smith.com</td>
</tr>
<div id="test">
<p>Test AFTER swap</p>
</div>
The <tbody>
section of the initial page will be modified as follows:
html
<tbody id="contacts-table">
<td>Joe Smith</td>
<td>joe@smith.com</td>
<tr>
<td>Cell 1a</td>
<td>Cell 1b</td>
</tr>
</tbody>
See how the <tr>
tag is removed. (cont.)prehistoric-garden-45720
02/04/2023, 11:10 PMhtmx.js
in master is modified from:
javascript
return swapStyle === "outerHTML";
to:
javascript
switch (swapStyle) {
case "outerHTML":
case "beforebegin":
case "afterbegin":
case "beforeend":
case "afterend":
return true;
default:
return false;
}
The swap occurs as I expect it to:
html
<tbody id="contacts-table">
<tr hx-swap-oob="afterbegin:#contacts-table">
<td>Joe Smith</td>
<td>joe@smith.com</td>
</tr>
<tr>
<td>Cell 1a</td>
<td>Cell 1b</td>
</tr>
</tbody>
orange-umbrella-16693
02/05/2023, 2:47 AMlocalStorage
instead of sessionStorage
for stuff like history?