How to disable / enable a dblclick JQuery event

2

Good morning, next, I'm trying to make a fast CRUD mode, in editing, for example, ADM gives 2 clicks in the field to be edited, and the field becomes editable with 2 buttons on the right, one to confirm and another to cancel.

What I have done is:

link

Make the following example:

Give Roberto Afonso a 2-click, now give him 2 more clicks. Notice that the text is deleted.

My idea was to prevent this "dlbClick" from being run, until the X or V icon was clicked, then it continued normal ..

How can I do this?

Thank you to whom to respond!

    
asked by anonymous 28.08.2016 / 19:06

1 answer

2

Since you are already adding the class celulaEmEdicao when dlbClick occurs, then you can simply check if the class is there and stop execution if it is.

So:

$("td").dblclick(function(e) {
    var originalContent = $(this).text();
    if ($(this).hasClass("celulaEmEdicao")) return e.preventDefault();
    $(this).addClass("celulaEmEdicao");
    // etc...
    
28.08.2016 / 20:52