Support event names with "." character (#1453)

hx-on throws an error when used with event names that contain dots
This commit is contained in:
Sascha Woo
2023-09-14 18:58:42 +02:00
committed by GitHub
parent f15795e79c
commit 81ac34994a
2 changed files with 9 additions and 1 deletions

View File

@@ -1972,7 +1972,7 @@ return (function () {
var curlyCount = 0;
while (lines.length > 0) {
var line = lines.shift();
var match = line.match(/^\s*([a-zA-Z:\-]+:)(.*)/);
var match = line.match(/^\s*([a-zA-Z:\-\.]+:)(.*)/);
if (curlyCount === 0 && match) {
line.split(":")
currentEvent = match[1].slice(0, -1); // strip last colon

View File

@@ -136,4 +136,12 @@ describe("hx-on attribute", function() {
}
calledEvent.should.equal(true);
});
it("can handle event types with dots", function () {
var btn = make("<button hx-on='my.custom.event: window.foo = true'>Foo</button>");
btn.dispatchEvent(new CustomEvent('my.custom.event'));
window.foo.should.equal(true);
delete window.foo;
});
});