-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fetch hx-vals programatically #2717
Comments
That function is published via the internalAPI as you found. You can access it by creating your own simple custom htmx extension as these are trivial to create. The internalAPI is passed to the extension init command and you can store this for later use. You can probably then export this and start using it. But you can also maybe do an onEvent function as well that will intercept standard htmx issued events so when the user interacts with the element with your extension tagged on it you can perform your own custom Ajax request for your use case using all the internalapi helpers to make things simpler and more htmx compatible. So instead of having your own custom vanilla JS trying to do actions scoped to the whole page you can move it to a more locality of behavior model where your custom functionality only applies to the few page elements you tag with hx-ext="my-cust-hack" You can also just put your ext on the body to apply everywhere and create your own custom event name and just listen for this name and use the internal api functions and trigger this event from your custom JS. |
Thank you for the suggestions!
I guess it could work, but it would be a hack.
I don't think in my case creating a custom htmx extension would look like a natural design. For now my workaround is to use invisible input tags instead of P.S. If P.P.S. I'm in general not a fan of over-protectiveness in third-party libraries. For me, as a consumer, it'd be more convenient to have access to private functions when I understand the risks and really need them. So for example, instead of hiding |
I want to make an AJAX request from JS using some data from a server which is already in HTML in the
hx-vals
attribute.There seems to be an internal API function getExpressionVars for this purpose. It could be convenient to make it public.
The text was updated successfully, but these errors were encountered: