Reputation: 61
I am using following code to tab through form elements using enter key. Problem is that this code skip select2 elements.
$('body').on('keydown', 'input, select', function(e) {
if (e.key === "Enter") {
var self = $(this), form = self.parents('form:eq(0)'), focusable, next;
focusable = form.find('input,a,select,button,textarea').filter(':not([disabled]):not([tabindex="-1"]):visible');
next = focusable.eq(focusable.index(this)+1);
if (next.length) {
next.focus();
} else {
//form.submit();
}
return false;
}
});
Upvotes: 0
Views: 435
Reputation: 4054
Change your keydown
to keyup
$('body').on('keyup', 'input, select', function(e)
Reason is keydown
is already handled in select2
library for choosing an item
Upvotes: 1