question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trigger other elements

See original GitHub issue

Hi everybody, a little bit of a background from my side: I worked at a company where we build a similar framework like htmx for internal usage. So I was excited to see the very same idea in the wild last year. Then I decided to use htmx for a small side-project of mine.

Looking at https://htmx.org/examples/ and sifting through the reference however it became clear that there was one important use-case not obviously being covered (or I’m didn’t find it in the docs). Think of the following situation in pseudo-html:

<html>
    <body>
        <stuff>
        <list of things>
        <other stuff>
        <create-form>
        <yet other stuff>

When the create-form successfully created a new object, the list of things should be updated as well as the create-form being reset for yet another post. And the rest of the stuff, body or html should not be touched or triggered.

This brings me to the proposal:

Reloading multiple others hx-elements by triggering them.

Or alternatively:

Let’s add an example for a create-form with updating other elements after successful form submission (if that’s already possible).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:14 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
1cgcommented, Mar 13, 2021

The preferred way of doing this would be to use the htmx events, either with vanilla javascript or hyperscript.

Here’s what the hyperscript would look like:

<form hx-post="/my-post" 
          _="on htmx:afterSwap trigger event-after-form-submit">
   ...
</form>
1reaction
srkunzecommented, Mar 13, 2021

@ribeiropaulor Custom events sound really cool. I don’t know if hx-target is really necessary but hx-dispatch-after-swap seem to do the trick here.

@1cg What is your opinion on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Click on an element triggers the click on another element ...
I would try it this way: $(document).on('click', '#contact', function(event) { event.preventDefault(); $("#contattaci h2").click(); });.
Read more >
Triggers and animations - Webflow University
You can add element triggers in the Element triggers section of the Interactions panel. These triggers start an animation when a site visitor...
Read more >
Clicking an element trigger to another element in jQuery
In this tutorial, we are going to see how to trigger the click on an element to another element using jQuery. Here we...
Read more >
How to trigger an event on an element when we click on ...
First, is fileInput a component? If so, you need access the components $el attribute to get to the DOM node. Second, if the...
Read more >
Creating and triggering events - MDN Web Docs - Mozilla
This article demonstrates how to create and dispatch DOM events. Such events are commonly called synthetic events, as opposed to the events ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found