Open jeffreyhwang opened 4 months ago
I have just built a working prototype for this, but then I stumbled upon https://github.com/thymeleaf/thymeleaf/issues/705. It seems support for things like:
<div th:onclick="|doSomething('${mydata}');|">
is no longer supported, because it can lead to unsafe things. I think we should respect this, and also not add support for hx:on
in this library.
That said, I am still a bit on the fence since you can today already use th:hx-on::before-request
, so if we would add support for having hx:on::before-request
, it would not matter that much.
In all honesty, I am not sure it is that useful, because if you do this for example:
<div id="hx-on-div" hx:on:click="|console.log('${stringVariable}')|"></div>
It would render as:
<div id="hx-on-div" hx-on:click="console.log('someString')"></div>
(Assuming the value of stringVariable
in the model is someString
)
@xhaggi @checketts I would love to hear your input on this as well.
I don't use Thymeleaf in my projects, so it's up you.
@jeffreyhwang Do you have an example where you might actually use this? I feel that you can't actually use this in a concrete example because of the escaping that happens, but I might be wrong.
Looking at the https://github.com/wimdeblauwe/htmx-spring-boot/blob/69fb0e1604a4fc97d97681df9a37f69b3054e1c5/htmx-spring-boot-thymeleaf/src/main/java/io/github/wimdeblauwe/htmx/spring/boot/thymeleaf/HtmxDialect.java#L27-55, it doesn't look like
hx:on
is supported.When I try to use it in thymeleaf, it looks like
hx:on
is being rendered ashx:on
, nothx-on
.Alternative that works is using
th:hx-on::before-request
, but I was wondering if there is a way to usehx:on
to keep things consistent.Thank you!