Skip to content
This repository has been archived by the owner on Nov 8, 2017. It is now read-only.

Unbind key will not work #47

Open
carstenschaefer opened this issue Oct 16, 2013 · 0 comments
Open

Unbind key will not work #47

carstenschaefer opened this issue Oct 16, 2013 · 0 comments

Comments

@carstenschaefer
Copy link

Hi there!

I have a modal popup which shows a error message. At the bottom of this popup there is a button to close the popup and do some other things.
I'd like to close the popup while pressing enter and setting the focus to the button will not work.

So I have decided to use jwerty for this and I have the following binding:

jwerty.key('enter', function () { $("#btnClose2").click(); });

It works fine. But after the popup is closed the primary behaviour regarding pressing event should be restored so I'd like to unbind this immediately after the click on btnClose2 has occured.

I tried the two following possible solutions:
1)

jwerty.key('enter', function () {
    $("#btnClose2").click();
    $(window).off('keydown.jwerty');
});

Alternatively, jwerty.event will return a function which, when run, unbinds the event, so:

var unbind;
$(document).on('keydown', (unbind = jwery.event('enter', function () {
     $("#btnClose2").click();
     unbind();
}))); 

In both cases the unbinding will not work.

Please give me a hint how to solve this.

Many thanks for your help
Carsten

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants