JQuery autocomplete issue - Shift key behaves the same as return key

See: http://www.airbnb.com/

In the search bar, start typing "san f" (no quotes, all lowercase), then press Return (or Enter). San Francisco is auto-complete. It's good!

Now clear the search box and start over. type "San F" and arrow - "San Francisco" autocomplete as soon as you press Shift. This is not expected.

This happens in FF and Safari, but has not been tested elsewhere. I have looked at the jQuery autocomplete source code and everything looks fine.

Has anyone experienced this before?

+2


a source to share


3 answers


To work around this issue:

Add to the KEY object:

    SHIFT: 16,
    CTRL: 17,
    ALT: 18

      



And to the very top of the onChange function add:

if ( jQuery.inArray(lastKeyPressCode, [KEY.SHIFT, KEY.CTRL,
       KEY.ALT]) !== -1 )
                return; 

      

+1


a source


I think the autorun config is autoFill: true

defined. Remove this, it will fix the problem. But in this case, after writing "san f" it will not automatically fill in "san Francisco, CA".



+1


a source


Try the autocomplete search option like below:

$(function() {
var availableTags = [
  "ActionScript",
  "AppleScript",
  "Asp",
  "BASIC",
  "C",
  "C++",
  "Clojure",
  "COBOL",
  "ColdFusion",
  "Erlang",
  "Fortran",
  "Groovy",
  "Haskell",
  "Java",
  "JavaScript",
  "Lisp",
  "Perl",
  "PHP",
  "Python",
  "Ruby",
  "Scala",
  "Scheme"
];
$( "#tags" ).autocomplete({
  source: availableTags,
    search: function( event, ui ) {
       if(event.which == 16 || event.which == 17 )
        event.preventDefault();  
    }
});

      

0


a source







All Articles