Skip to content

Commit

Permalink
support hx-swap="none"
Browse files Browse the repository at this point in the history
fixes #89
  • Loading branch information
carson committed Jun 11, 2020
1 parent 5e8fbb2 commit 4ef719e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,8 @@ return (function () {

function swap(swapStyle, elt, target, fragment, settleInfo) {
switch (swapStyle) {
case "none":
return;
case "outerHTML":
swapOuterHTML(target, fragment, settleInfo);
return;
Expand Down
10 changes: 9 additions & 1 deletion test/attributes/hx-swap.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ describe("hx-swap attribute", function(){
}, 30);
});


it('swap outerHTML properly w/ data-* prefix', function()
{
this.server.respondWith("GET", "/test", '<a id="a1" data-hx-get="/test2">Click Me</a>');
Expand All @@ -262,5 +261,14 @@ describe("hx-swap attribute", function(){
byId("a1").innerHTML.should.equal('Clicked!');
});

it('swap none works properly', function()
{
this.server.respondWith("GET", "/test", 'Ooops, swapped');

var div = make('<div hx-swap="none" hx-get="/test">Foo</div>')
div.click();
this.server.respond();
div.innerHTML.should.equal('Foo');
});

})
1 change: 1 addition & 0 deletions www/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ with any of the following values:
| `beforebegin` | prepends the content before the target in the targets parent element
| `beforeend` | appends the content after the last child inside the target
| `afterend` | appends the content after the target in the targets parent element
| `none` | does not append content from respons (out of band items will still be processed)

#### <a name="oob_swaps"></a>[Out of Band Swaps](#oob_swaps)

Expand Down

0 comments on commit 4ef719e

Please sign in to comment.