-
Notifications
You must be signed in to change notification settings - Fork 493
Open
Description
I can't move to the next field when I open Select2. Also, the cursor doesn't automatically move to the search field.
Use the code to move between fields by pressing Enter.
this work with input and normal select and button but not working with select2
$(document).on('keydown', 'input, select, button', function(e) {
if (e.key === "Enter") {
const fields = $('input, select, button').filter(':visible'); // Select all visible fields
const currentIndex = fields.index(this); // Find the index of the currently focused field
let nextIndex = currentIndex + 1; // Start looking at the next field
while (nextIndex < fields.length) {
const nextField = fields[nextIndex]; // Get the next field
if (!nextField.readOnly) {
const $next = $(nextField);
if ($next.is('button') && $next.attr('id') === 'submit-form') {
// window.alert("document.getElementById.submit();");
var self = $(this);
form = self.parents('form:eq(0)');
form.submit();
// return;
} else {
e.preventDefault();
}
if ($next.is('button') && $next.attr('id') === 'calc') {
getCalculate();
}
nextField.focus();
break;
}
nextIndex++;
}
}
});
`
Metadata
Metadata
Assignees
Labels
No labels