Better-Autocomplete icon indicating copy to clipboard operation
Better-Autocomplete copied to clipboard

selectkey and autoHighlight bug

Open seif3r opened this issue 9 years ago • 0 comments

Using autocomplete with

  • selectKeys : [13],
  • autoHighlight: false

gives me the bug that I cannot use Enter to select the raw unhighlighted input.

// A select key has been pressed
    else if ($.inArray(event.keyCode, options.selectKeys) >= 0 &&
             !event.shiftKey && !event.ctrlKey && !event.altKey &&
             !event.metaKey) {
      select();
     return event.keyCode == 9; // Never cancel tab
    }

If I change the return keyCode to 13 or just comment the return line away it works the way I expect it too.

/** edit **/ After working on it a bit this is the solution i came up with, can probably be done alot better, but it seems to work.

      // A select key has been pressed
      else if ($.inArray(event.keyCode, options.selectKeys) >= 0 &&
              !event.shiftKey && !event.ctrlKey && !event.altKey &&
              !event.metaKey) {
        // With autoHighlight off and only Enter key as selectvalue this gives us a bug
        // This if -> else fixes it.
        if (index == -1 && (event.keyCode).inArray(options.selectKeys)) {
          select();
        }
        else {
          select();
          return event.keyCode == 9; // Never cancel tab
        }
      }

seif3r avatar Nov 16 '15 10:11 seif3r