miniature-lizard-24702
10/16/2022, 2:51 PMminiature-lizard-24702
10/16/2022, 2:52 PMminiature-lizard-24702
10/16/2022, 2:53 PMloud-action-20310
10/16/2022, 8:24 PMloud-action-20310
10/16/2022, 8:27 PMmammoth-family-48524
10/16/2022, 10:05 PMgorgeous-airport-54386
10/16/2022, 10:06 PMmammoth-family-48524
10/16/2022, 10:06 PMuser
10/16/2022, 10:33 PMid
attribute. Any way to do this without custom JS?ripe-action-67367
10/16/2022, 11:00 PMalpine-morph
, morphdom-swap
and brand new idiomorph
from 1cg himself.
What's your goal though? I imagine, there isn't much elements state to keep within search results?elegant-keyboard-60245
10/16/2022, 11:06 PMcuddly-keyboard-70746
10/16/2022, 11:39 PMcuddly-keyboard-70746
10/16/2022, 11:40 PMcuddly-keyboard-70746
10/16/2022, 11:40 PMmysterious-toddler-20573
10/17/2022, 12:06 AMsquare-oyster-36295
10/17/2022, 12:44 AMmulti-swap
extension. Now it works according to all our requirements.
js
(function () {
/** @type {import("../htmx").HtmxInternalApi} */
var api;
htmx.defineExtension('multi-swap', {
init: function (apiRef) {
api = apiRef;
},
isInlineSwap: function (swapStyle) {
return swapStyle.indexOf('multi:') === 0;
},
handleSwap: function (swapStyle, target, fragment, settleInfo) {
if (swapStyle.indexOf('multi:') === 0) {
var selectorToSwapStyle = {};
var elements = swapStyle.replace(/^multi\s*:\s*/, '').split(/\s*,\s*/);
elements.map(function (element) {
var split = element.split(/\s*:\s*/);
var elementSelector = split[0];
var elementSwapStyle = typeof (split[1]) !== "undefined" ? split[1] : "innerHTML";
if (elementSelector.charAt(0) !== '#') {
console.error("HTMX multi-swap: unsupported selector '" + elementSelector + "'. Only ID selectors starting with '#' are supported.");
return;
}
selectorToSwapStyle[elementSelector] = elementSwapStyle;
});
for (var selector in selectorToSwapStyle) {
var swapStyle = selectorToSwapStyle[selector];
var elementToSwap = fragment.querySelector(selector);
if (elementToSwap) {
api.oobSwap(swapStyle, elementToSwap, settleInfo);
} else {
console.warn("HTMX multi-swap: selector '" + selector + "' not found in source content.");
}
}
return true;
}
}
});
})();
square-oyster-36295
10/17/2022, 12:46 AMphp
<?php
$div1 = rand(0,99999999);
$div2 = rand(0,99999999);
$div3 = rand(0,99999999);
$random = rand(0,99999999);
?>
<html>
<head>
<title>Page <?php echo $random; ?></title>
<style type="text/css">
div { clear: both; display: block; }
</style>
<script src="htmx.js"></script>
<script src="htmx.multi-swap.js"></script>
</head>
<body hx-boost="true">
<h1>Heading (<?php echo $random; ?>)</h1>
<a href="index.php" hx-ext="multi-swap" hx-swap="multi:#id1,#id3:beforeend">Refresh</a>
<div id="id1"><?php echo $div1; ?></div>
<div id="id2"><?php echo $div2; ?></div>
<div id="id3"><?php echo $div3; ?></div>
</body>
</html>
square-oyster-36295
10/17/2022, 12:52 AM.foo
, but I couldn't find any other way to replace the content available in the internal API.eager-tiger-27508
10/17/2022, 3:39 AMmelodic-advantage-28381
10/17/2022, 6:37 AMrefined-pillow-25368
10/17/2022, 8:37 AMpolite-oil-80202
10/17/2022, 10:20 AMminiature-lizard-24702
10/17/2022, 11:49 AMelegant-keyboard-60245
10/17/2022, 11:56 AMcuddly-keyboard-70746
10/17/2022, 1:38 PMminiature-lizard-24702
10/17/2022, 2:51 PMcalm-ice-23682
10/17/2022, 3:09 PM<button hx-post="/clicked"
hx-trigger="click"
hx-target="#output-area"
hx-swap="outerHTML"
hx-condition="!exists #item2"
>
Click Me!
</button>
<div id="output-area"></div>
<div id="container-for-things-to-check">
<p id="item1">item one</p>
<p id="item3">item three</p>
<p id="item4">item four</p>
</div>
calm-ice-23682
10/17/2022, 3:11 PMripe-action-67367
10/17/2022, 3:15 PMpreventDefault
when condition is not met (can also be done with _hyperscript)
3. Define a JS function and use event filters (e.g., click[!elementExists()]
). The function must be in the global scopecalm-ice-23682
10/17/2022, 3:19 PM