Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
HTMX multiple event on one element - each event executing different request

Summary, How do I attach a click and a dblclick on same element in HTMX and also have each of the event executing different request (views).

.I am new to HTMX using django and i have this list

   <li class="list-group-item"
        hx-get="{% url 'quality:list'  competence.pk  %}"
        hx-target="#quality-list"
        hx-trigger="click"
        >

it works fine using the click event. I however also want it to execute another view (quality:update) when a dblclick is fired on it. i.e. on same element (li) click should implement details function and dblclick should implement update function

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

We can modify the request path in the htmx:configRequest HTMX-event depending on the triggering event's type. First, we need to list the triggering events in the hx-trigger attribute. However for the single click event, we also need to add some delay, otherwise the single click event will be also fired twice before the double click event. I set the delay here to 0.5 second, but you can fine tune it for your needs/target audience.

<li class="list-group-item"
    hx-get="{% url 'quality:list' competence.pk %}"
    hx-target="#quality-list"
    hx-trigger="click delay:0.5s, dblclick"
    >

We can alter the path in the evt.detail.path property and we can check the triggering event's type at evt.detail.triggeringEvent.type:

<script>
document.body.addEventListener('htmx:configRequest', function(evt) {
    evt.detail.path = (evt.detail.triggeringEvent.type === 'dblclick') ? 
      '{% url 'quality:update' competence.pk %}' : 
      '{% url 'quality:list' competence.pk %}'
});
</script>

This small snipped can be placed anywhere in a Django template file.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!