Closed justinguk closed 9 years ago
So the problem you are seeing is that when a user has selected a text field, you are calling stop_listening() on your listener, but when you type into the text field, your combos are being activated? Perhaps you are also immediately calling start_listening() as well. Do you have a code sample to demonstrate this issue?
HI David,
$(document).ready(function() {
var listener = new window.keypress.Listener();
listener.sequence_combo("shift g o", function() {
window.location.href = "app/view-orders";
});
$('input').bind("focus", listener.stop_listening)
.bind("blur", listener.listen);
});
Whenever I place a console.log event in the stop_listening part of the code, I can see it's being fired but the actual listener event doesn't seem to stop.
It's better to use
$('input').focus(function(){console.log("got focus")});
now
Replacement for .bind("blur") is just blur(func)
The problem with your code sample is that you're calling stop_listening as if it were a function instead of a method. The value of this
in that method is important. Try this:
$(input).bind("blur", function() { listener.stop_listening(); });
That should do it.
Just realized I made this mistake in my documentation :0 Sorry about that. Fixed: https://github.com/dmauro/Keypress/pull/80
When binding stop_listening() to the user being focused on a text field, it should prevent prevent capture, but something doesn't prevent the listener from listening.