Reputation: 559
I am using Mousetrap for create keyboard shortcuts, it was not working when any fields in focus. This is the link for view demo http://davidwalsh.name/keyboard-shortcuts from where i get the code. when i use to call
Mousetrap.bind('ctrl+m', function () {
var button = $('[data-action="next-page"]');
if (button.length) {
button[0].click()
}
});
like this it not working , when mouse points in text-box or drop-down etc,. Can any give solution for me. Thanks in advance.
Upvotes: 16
Views: 6233
Reputation: 363
If you're using input or textarea or select elements, you must define the mousetrap class:
<textarea name="message" class="mousetrap"></textarea>
See the "Text fields" section in the oficial doc at https://craig.is/killing/mice
Upvotes: 2
Reputation: 668
By default mousetrap disable the shortcuts when the focus is on input fields, dropdown, etc..
If your problem is with only one field, include the class mousetrap
in it.
If you want to disable all scenarios try the following code
Mousetrap.stopCallback = function () {
return false;
}
This will overwrite the initial behavior and allow shortcuts in any field of the screen.
Upvotes: 30