htmx icon indicating copy to clipboard operation
htmx copied to clipboard

Support Javascript-based requests

Open sirinath opened this issue 5 years ago • 7 comments

Can hx-js be added so content can be returned by JS.

<div hx-js="clicked()"
       hx-trigger="click"
       hx-target="#parent-div"
       hx-swap="outerHTML">
    Click Me!
</div>

sirinath avatar Jun 18 '20 04:06 sirinath

maybe we should support the "javascript:" standard from anchor tags:

<a href="javascript:show_more_menu();">More >>></a>

https://stackoverflow.com/questions/7347786/html-anchor-tag-with-javascript-onclick-event

1cg avatar Jun 18 '20 14:06 1cg

Also worth pondering:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs

1cg avatar Jun 18 '20 14:06 1cg

I think the options to have JavaScript or data can replace content would be a great addition. Also using the standard javascript: and data: would be the best options. Also in the case of JS JSX also can be supported.

sirinath avatar Jun 18 '20 15:06 sirinath

we have an open branch exploring this option now:

https://github.com/bigskysoftware/htmx/tree/feature_js_expression_support

1cg avatar Jul 06 '21 21:07 1cg

It's been a few years, what's the status on this? Is it still something that is being looked into? If any assistance is needed l'll try to contribute where I can.

waffles-dev avatar Sep 24 '24 23:09 waffles-dev

Is it still something that is being looked into?

Likely not! If it were to be implemented today though, we'd ask for it to start as an extension and not directly added to the core library. If you want to give a shot at implementing this @TastyWaffles , please feel free to do so! You'll want to take a look at the extensions repo as well as the extensions website deployed from it, where we have a section to list community extensions.

Telroshan avatar Sep 25 '24 07:09 Telroshan

Thanks! I'm happy to take a look, no promises though!

waffles-dev avatar Sep 25 '24 07:09 waffles-dev