enfocus icon indicating copy to clipboard operation
enfocus copied to clipboard

event handler functions within hiccup-html

Open seprich opened this issue 9 years ago • 2 comments

Hi, I am not sure whether this is supposed to be supported or not:

(defn set-application []
  (let [content (ef/html [:div [:h1 "Testing"]
                          [:button {:onclick #(.log js/console "TESTING")} "Test it!"]])]
    (ef/at ["#application"] (ef/content content))))

Anyway the onclick function is broken and does not work in chromium nor in firefox. In both I get "Uncaught SyntaxError: Unexpected token (" . ~~pointing just to the first line of my index.html without decent explanation (and I have the .js.map file in place).~~ The generated html looks like this:

<div>
    <h1>Testing</h1>
    <button onclick="function (){return console.log(&quot;Hi there!&quot;)}">Test it!</button>
</div>

This inlined js is clearly broken (at the very least something like "(function () {...})()" -wrapping is missing). Anyway supporting embedded event handlers would be a powerful feature.

seprich avatar Oct 11 '15 01:10 seprich

This looks to be an easy fix. Will try to get it in this weekend.

ckirkendall avatar Oct 16 '15 18:10 ckirkendall

If you could can you pull down the latest and do an lein install and test it with your app before I make a release. I pushed up the fix.

ckirkendall avatar Oct 16 '15 19:10 ckirkendall