Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherit support include indicator - correction #2305

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,14 @@ return (function () {
return [window];
} else if (selector === 'body') {
return [document.body];
} else if (selector.indexOf("inherit") === 0) {
var result = [...Array.prototype.slice.call(getDocument().querySelectorAll(normalizeSelector(selector)))]
var attrTarget = getAttributeValue(elt, 'hx-include')
if (attrTarget){
result.push(...Array.prototype.slice.call(querySelectorAllExt(elt.parentNode, attrTarget)))
result.filter((value, index, array) => array.indexOf(value) === index)
}
return result;
} else {
return getDocument().querySelectorAll(normalizeSelector(selector));
}
Expand Down
17 changes: 16 additions & 1 deletion test/attributes/hx-include.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,22 @@ describe("hx-include attribute", function() {
this.server.respond();
btn.innerHTML.should.equal("Clicked!");
})

it('The `inherit` modifier can be used in the hx-include selector', function () {
this.server.respondWith("POST", "/include", function (xhr) {
var params = getParameters(xhr);
params['i1'].should.equal("test");
params['i2'].should.equal("test");
xhr.respond(200, {}, "Clicked!")
});
make('<input id="i2" name="i2" value="test"/>');
var div = make('<div hx-include="#i2" hx-target="this">'+
'<input id="i1" name="i1" value="test" hx-post="/include" hx-trigger="click" hx-include="inherit, #i1"/>'+
'</div>');
var input = byId("i1")
input.click();
this.server.respond();
div.innerHTML.should.equal("Clicked!");
})
it('The `this` modifier can be used in the hx-include selector', function () {
this.server.respondWith("POST", "/include", function (xhr) {
var params = getParameters(xhr);
Expand Down