Alex
Alex

Reputation: 67732

Disable a event during the time a different event is active

Can I do this:

$('.box').delegate('.edit', 'click', function(edit_event){   

  ... 
  var input = $('input', this);

  input.focus().bind('blur keypress', function(event){   

    // here disable the first .edit event (don't allow click on that element)?

  });

});

the event would be enabled again if certain conditions are met inside the 2nd event (and when a AJAX call is complete)

Upvotes: 1

Views: 119

Answers (1)

user113716
user113716

Reputation: 322562

Since you're using the delegate()[docs] method, which is selector based, you could just add a class to the current .edit that excludes it from the selector.

 // only invoke if it has "edit" class and not "disable" class
$('#box').delegate('.edit:not(.disable)', 'click', function (edit_event) {

      // add the class to this edit element to disable it
    var edit = $(this).addClass('disable');
    var input = $('input', this);

    input.focus().bind('blur keypress', function (event) {

        // here disable the first .edit event (don't allow click on that element)?

        // after some work, remove the class to re-enable the click
        edit.removeClass('disable');
    });

});

I used the not-selector[docs] so that the click event won't fire until the disable class is removed.

Upvotes: 2

Related Questions