mercredi 25 mars 2020

Preventing double-click on checkbox with label

Today I got very interesting situation and really want to find solution. I found a lot of similar topics, but answers don't helps.

So I need to prevent doubleclick on my checkbox with Jquery. First of all I tried the simplest way:

$("input[type='checkbox']", this).dblclick(function() {
    alert( "Double Clicked" );
});

But alert don't coming up on dblclick. I found an solution like this:

$("input[type='checkbox']", this).on("change", function() {
    $("input[type='checkbox']", this).prop('disabled', true);
    sleep(750).then(() => {
        $("input[type='checkbox']", this).prop('disabled', false);
    }) 
})

This event is nicely triggered, but checkbox not disabled for 750ms (but if I put alerts, alert coming at right time, when button must enabled/disabled) and I am still able to double-click on it. Any solution for this?




Aucun commentaire:

Enregistrer un commentaire