You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am triggering htmx.ajax but my response contains a full page and I am trying to swap a part of the response
What I am doing is working but seems really silly is there a cleaner way to do it?
Another solution would be to configure properly the element "#inner-page" using the hx- markup and trigger an event, but I can't find a way to replace the value of hx-get. I used setAttribute but seems to be ignored
<div class="lg:w-98% w-75% flex flex-col gap-8 relative" id="inner-page" hx-trigger="filter-event" hx-target="this" hx-swap="outerHTML" hx-push-url="true">
old data
</div>
let inner = htmx.find("#inner-page")
inner.setAttribute("hx-get", new_url)
htmx.trigger(inner, "filter-event")
Thanks for your help
Reacted by Rafael Martins, Aral Balkan and Steven Prins
@Benoss -- Your second solution is the better way to go, with one small change. If you're dynamically changing the value of hx-get, you need to tell htmx about the change. Put htmx.process(node) at the end of your Javascript and it should update correctly.
@1cg -- Unless we're changing event handlers that are registered via hx-trigger I don't see why htmx couldn't just look up the action (hx-get, hx-post, hx-delete, hx-put) dynamically when the element is activated. It might even save a small amount of up-front processing. Is there a reason this needs to be scanned and cached ahead of time?
Agree w/ you ben, no reason to aggressively cache the request URL. But I think the crux here is that the htmx.ajax() function needs more functionality. We need to include a select option, just like we have a target option:
@1cg, are there any plans to implement select option of htmx.ajax() in the near future? Definitely a useful thing, it would simplify the writing of a server-side HTML render function.
I ran into this issue where I needed "select" on the ajax javascript function a couple days ago and wouldn't mind taking a crack at implementing it. Is it still on the list of things that need doing?
Activity
benpate commentedon Dec 9, 2021
@Benoss -- Your second solution is the better way to go, with one small change. If you're dynamically changing the value of
hx-get, you need to tell htmx about the change. Puthtmx.process(node)at the end of your Javascript and it should update correctly.@1cg -- Unless we're changing event handlers that are registered via
hx-triggerI don't see why htmx couldn't just look up the action (hx-get, hx-post, hx-delete, hx-put) dynamically when the element is activated. It might even save a small amount of up-front processing. Is there a reason this needs to be scanned and cached ahead of time?1cg commentedon Jan 16, 2022
Agree w/ you ben, no reason to aggressively cache the request URL. But I think the crux here is that the htmx.ajax() function needs more functionality. We need to include a
selectoption, just like we have atargetoption:https://htmx.org/api/#ajax
I'll add it to the list
applecat commentedon Nov 8, 2022
@1cg, are there any plans to implement
selectoption ofhtmx.ajax()in the near future? Definitely a useful thing, it would simplify the writing of a server-side HTML render function.mardix commentedon Dec 21, 2022
Can we get the select
selectoption added in htmx.ajax?ece-jacob-scott commentedon Nov 9, 2023
@1cg
I ran into this issue where I needed "select" on the ajax javascript function a couple days ago and wouldn't mind taking a crack at implementing it. Is it still on the list of things that need doing?
Benoss commentedon Jun 10, 2024
Just realised that this is now fixed since version 1.9.9 and that I should close the issue
https://github.com/bigskysoftware/htmx/blob/master/CHANGELOG.md#199---2023-11-21