mirror of
https://github.com/bigskysoftware/htmx.git
synced 2026-01-25 05:06:13 +00:00
Merge in headers from https://github.com/bigskysoftware/htmx/pull/3533 (leave HX-Request-Type out for now until we discuss)
This commit is contained in:
@@ -302,7 +302,7 @@ var htmx = (() => {
|
||||
status: "created",
|
||||
select: this.__attributeValue(sourceElement, "hx-select"),
|
||||
selectOOB: this.__attributeValue(sourceElement, "hx-select-oob"),
|
||||
target: this.__attributeValue(sourceElement, "hx-target"),
|
||||
target: this.__resolveTarget(sourceElement, this.__attributeValue(sourceElement, "hx-target")),
|
||||
swap: this.__attributeValue(sourceElement, "hx-swap", this.config.defaultSwap),
|
||||
push: this.__attributeValue(sourceElement, "hx-push-url"),
|
||||
replace: this.__attributeValue(sourceElement, "hx-replace-url"),
|
||||
@@ -346,6 +346,8 @@ var htmx = (() => {
|
||||
__determineHeaders(elt) {
|
||||
let headers = {
|
||||
"HX-Request": "true",
|
||||
"HX-Source": elt.id || elt.name,
|
||||
"HX-Current-URL": location.href,
|
||||
"Accept": "text/html, text/event-stream"
|
||||
};
|
||||
if (this.__isBoosted(elt)) {
|
||||
|
||||
@@ -33,12 +33,12 @@ describe('__handleTriggerEvent unit tests', function() {
|
||||
assert.isTrue(evt.defaultPrevented)
|
||||
})
|
||||
|
||||
it('preserves target selector in ctx.target', async function () {
|
||||
it('resolves target from ctx.target', async function () {
|
||||
createProcessedHTML('<div id="target"></div><button hx-get="js:" hx-target="#target"></button>')
|
||||
let button = document.querySelector('button')
|
||||
let ctx = htmx.__createRequestContext(button, new Event('click'))
|
||||
await htmx.__handleTriggerEvent(ctx)
|
||||
assert.equal(ctx.target, '#target')
|
||||
assert.equal(ctx.target.id, 'target')
|
||||
})
|
||||
|
||||
it('collects form data from element', async function () {
|
||||
|
||||
@@ -1134,8 +1134,10 @@ htmx includes headers in the requests it makes:
|
||||
| Header | Description |
|
||||
|------------------------------|------------------------------------------------------------------------------------------------------|
|
||||
| `HX-Boosted` | indicates that the request is via an element using [hx-boost](@/attributes/hx-boost.md) |
|
||||
| `HX-Current-URL` | the current URL of the browser |
|
||||
| `HX-History-Restore-Request` | "true" if the request is for history restoration after a miss in the local history cache |
|
||||
| `HX-Request` | always "true" except on history restore requests if `htmx.config.historyRestoreAsHxRequest' disabled |
|
||||
| `HX-Source` | the `id` or `name` of the element that triggered the request |
|
||||
|
||||
### Response Headers
|
||||
|
||||
|
||||
@@ -78,8 +78,10 @@ All other attributes available in htmx.
|
||||
| Header | Description |
|
||||
|--------|-------------|
|
||||
| `HX-Boosted` | indicates that the request is via an element using [hx-boost](@/attributes/hx-boost.md)
|
||||
| `HX-Current-URL` | the current URL of the browser
|
||||
| `HX-History-Restore-Request` | "true" if the request is for history restoration
|
||||
| `HX-Request` | always "true" for htmx-initiated requests
|
||||
| `HX-Source` | the `id` or `name` of the element that triggered the request
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user