select2-bootstrap-theme icon indicating copy to clipboard operation
select2-bootstrap-theme copied to clipboard

can not go to next filed after open select2-bootstrap-theme

Open swadallail opened this issue 6 months ago • 0 comments

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++;
      }
    }
  });

  
`

swadallail avatar Apr 23 '25 07:04 swadallail