htmx.ajax, HtmxAjaxHelperContext typedef requires target, specfying source element #2698
Unanswered
anentropic
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
Hey, I'm the one who wrote this JSDoc and you're right, this must have been an oversight, it's completely optional as htmx uses the regular hx-target as a fallback: Line 4062 in 6c2f9ea I also agree that the Feel free to open a documentation fix PR if you feel like it! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using
htmx.ajaxin an event handler to load a new page.I want the request to inherit the
hx-*properties of the ancestor element like it would do if I was making it via anhx-getattribute.The third arg to
htmx.ajaxaccepts acontextobject with various properties... e.g.target,selectandswaphave the same effect as settinghx-target,hx-select,hx-swapattrs on the element or its ancestors.It's not really spelled out in the docs but I also found that setting
sourceelement seems to allow the ajax request to inherit thehx-*properties (for examplehx-push-url="true") of its ancestor - 👍 exactly what I wanted, rather than having to pass them down into my component in order to send them in the ajax context.So I have an event handler that looks something like
(e) => htmx.ajax("get", url, {event: e, source: e.target})and it works as I want.The only issue I have is when working in TypeScript, the third argument is typed as a
HtmxAjaxHelperContext. The definition is like:So this type makes
targeta required field. But I don't want to specify thetarget, I want it to inherit thehx-targetfrom the ancestor ofsource.And if I just ignore/workaround the typedef and pass
{event: e, source: e.target}as my context then it seems to work fine.So I'm asking if perhaps
HtmxAjaxHelperContexttypedef should make all fields optional?Beta Was this translation helpful? Give feedback.
All reactions