Skip to content

Commit 117d658

Browse files
Allow custom methods like query (#3892)
* Allow custom methods like query * remove test for invalid methods. fetch allows almost any method
1 parent 7a8108f commit 117d658

4 files changed

Lines changed: 11 additions & 10 deletions

File tree

src/htmx.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ var htmx = (() => {
527527
})
528528

529529
if (!this.__trigger(elt, "htmx:config:request", {ctx: ctx})) return
530-
if (!this.#verbs.includes(ctx.request.method.toLowerCase())) return
530+
if (ctx.request.method === 'DIALOG') return
531531

532532
let javascriptContent = this.__extractJavascriptContent(ctx.request.action);
533533
if (javascriptContent != null) {

test/lib/fetch-mock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class FetchMock {
8585
// Mock a response for a specific URL pattern
8686
mockResponse(method, urlPattern, response, options = {}) {
8787
let upperCasedMethod = method.toUpperCase();
88-
if (['GET', 'POST', 'PUT', 'PATCH', 'DELETE'].indexOf(upperCasedMethod) < 0) {
88+
if (['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'QUERY'].indexOf(upperCasedMethod) < 0) {
8989
throw Error("Invalid HTTP method: " + method)
9090
}
9191
if (typeof response === 'string') {

test/tests/attributes/hx-action.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,13 @@ describe('hx-action attribute', function() {
5353
playground().innerHTML.should.equal('Put!')
5454
})
5555

56+
it('hx-action with hx-method QUERY issues a QUERY request', async function() {
57+
mockResponse('QUERY', '/test', 'Queried!')
58+
let btn = createProcessedHTML('<button hx-action="/test" hx-method="QUERY">Click Me!</button>')
59+
btn.click()
60+
await forRequest()
61+
fetchMock.calls[0].request.method.should.equal('QUERY')
62+
btn.innerHTML.should.equal('Queried!')
63+
})
64+
5665
})

test/tests/unit/__handleTriggerEvent.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,6 @@ describe('__handleTriggerEvent unit tests', function() {
107107
assert.isUndefined(window.testExecuted)
108108
})
109109

110-
it('returns early if method not in verbs list', async function () {
111-
let div = createProcessedHTML('<div hx-get="js:window.testExecuted = true"></div>')
112-
let ctx = htmx.__createRequestContext(div, new Event('click'))
113-
ctx.request.method = 'INVALID'
114-
await htmx.__handleTriggerEvent(ctx)
115-
assert.isUndefined(window.testExecuted)
116-
})
117-
118110
it('executes javascript when action starts with js:', async function () {
119111
let div = createProcessedHTML('<div hx-get="js:window.testExecuted = true"></div>')
120112
let ctx = htmx.__createRequestContext(div, new Event('click'))

0 commit comments

Comments
 (0)