Add custom HTMX actions #1709
infuzu-yidisprei
started this conversation in
Ideas
Replies: 1 comment
-
Not sure if discussions cross-link like issues do, but I had similar question regarding arbitrary actions in response to event triggers: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First thing is first, I am a really big fan of HTMX and I would love to see it implemented much further than it is now. I want to see it implemented beyond just triggering AJAX requests. I think the future for HTMX is much wider and much more capable.
I already submitted an issue about this but I would love everyone's input on the idea. #1708
I was working on building an extension for HTMX in order to make it able to toggle classes on the target rather than making an ajax request. I ended up succeeding (https://github.com/yidispreiyidienterprises/HTMX-Classify) but the way I managed to do it was by creating a fake get request and intercepting the error message for it. The problem was the htmx won't register an event (regardless of the trigger) unless there is a specified ajax request. We should be able to have custom actions without specifying an ajax request. This would make javascript a lot more minimalist and in line with htmx's mission.
and then in the extension I would intercept the bad requests.
This shouldn't be necessary. It would be amazing if htmx supported custom actions.
so, for example, you should be able to specify
hx-action="ajax-get:/some-random-url"
and that would be equivalent tohx-get="/some-random-url"
. The same functionality should be possible for custom actions. for example, you should be able to specifyhx-action="custom:randomJSFunction"
and htmx should pass the target element to the function.Another great use of this would be to allow extensions to specify their own actions. For example, in my case of
classify
I would be able to build the extension by registering a custom action that would be able to function ashx-action="classify-add:random-new-class"
Beta Was this translation helpful? Give feedback.
All reactions