diff options
author | Denis Palashevskii <20725046+Renerick@users.noreply.github.com> | 2023-10-26 21:54:24 +0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-26 11:54:24 -0600 |
commit | a679244c40fd7eb61c87d7293b51b8806b3d32e3 (patch) | |
tree | 254c4d53aa09ae4828a756746018ba96191b91a8 | |
parent | 0718daa3ac62dfba0c20e357a66fbf24d2169392 (diff) | |
download | htmx-a679244c40fd7eb61c87d7293b51b8806b3d32e3.tar.gz htmx-a679244c40fd7eb61c87d7293b51b8806b3d32e3.zip |
Fix websocket polling trigger (#1903)
fix websocket polling trigger
-rw-r--r-- | src/ext/ws.js | 2 | ||||
-rw-r--r-- | test/ext/ws.js | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/ext/ws.js b/src/ext/ws.js index afd82995..3366e9e5 100644 --- a/src/ext/ws.js +++ b/src/ext/ws.js @@ -379,7 +379,7 @@ This extension adds support for WebSockets to htmx. See /www/extensions/ws.md f socketWrapper.send(body, elt); - if (api.shouldCancel(evt, elt)) { + if (evt && api.shouldCancel(evt, elt)) { evt.preventDefault(); } }); diff --git a/test/ext/ws.js b/test/ext/ws.js index 96de6009..7e6f140d 100644 --- a/test/ext/ws.js +++ b/test/ext/ws.js @@ -172,6 +172,18 @@ describe("web-sockets extension", function () { this.messages.length.should.equal(1); }) + it('sends data to the server with polling trigger', function () { + var div = make('<div hx-ext="ws" ws-connect="ws://localhost:8080"><div hx-trigger="every 1s" ws-send id="d1">div1</div></div>'); + this.tickMock(); + this.clock.tick(2000); + + byId("d1").click(); + + this.tickMock(); + + this.messages.length.should.equal(2); + }) + it('sends expected headers to the server', function () { var div = make('<div hx-ext="ws" ws-connect="ws://localhost:8080"><button hx-trigger="click" hx-target="#target" ws-send id="d1" name="d1-name">div1</button><output id="target"></output></div>'); this.tickMock(); |