bigskysoftware / htmx

</> htmx - high power tools for HTML
https://htmx.org
Other
37.89k stars 1.29k forks source link

How to prevent another htmx click if it's still in 1 card? #662

Closed fikryrmdhna closed 2 years ago

fikryrmdhna commented 2 years ago

image

I have a product detail card where the whole card can be clicked and then a details popup will appear and it is triggered by htmx. Then on the card there is a Pesan Ulang button which triggered by htmx.

Currently, when I click Pesan Ulang, the htmx to display the details popup is also triggered.

My question is, how I do that when I click Pesan Ulang, only htmx for Pesan Ulang is triggered, not product detail popup?

I've tried to handle it with javascript but it's still triggered. Is there a way in htmx to handle this?

@formatDateTime(order.getCreatedAt()) WIB @if(order.getStatus().toString().equals("PENDING_PAYMENT")) {
} else {
} @if(order.getStatus().toString().equals("PENDING_PAYMENT")) { } else {
}
Nomor Pesanan
@if(order.getFormattedBusinessId().isEmpty()){-}else{@order.getFormattedBusinessId()}
Status
-
Total Belanja
Rp @fbd(order.getPaymentAmount())
@with(OrderHistoryLine line = order.getLine()) {
lenovo
@line.getName()
@line.getMpn()
Rp @fbd(line.getUnitPricePreTax())
} @if(order.isEligibleToDoPayment()) { @if(!isNull(order.getMidtransTransactionId())) { } else { } }
@if(order.isEligibleToReorder()) {
}

Javascript

<script>
    $(".order-detail-@order.getOrderId()").each(function() {
        $(this).on("click.div", function() {
            $('.order-detail-trigger-@order.getOrderId()').trigger('click.button');
        })
    });

   $("#orderReorder").on("click", function() {
      $(this).siblings().click();
   });
</script>
1cg commented 2 years ago

Sorry this has taken so long to respond to.

If I understand you have two different elements that are being triggered by click but one is nested in the other, so when you click the inner object, both trigger.

The solution here would be to use the event filter on triggers and check the event.target in the outer element, and ensure it isn't the inner element.