user237005
user237005

Reputation: 51

jQuery Autocomplete problem - Shift Key behaves same as Return Key

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

In the search bar, start typing "san f" (no quotes, all lowercase), then hit Return (or Enter). "San Francisco" is autocompleted. This is good!

Now clear the search field and start over. type "San F" and boom - "San Francisco" is autocompleted as soon as you hit Shift. This is not expected.

This happens in FF & Safari, but is untested elsewhere. I've looked through the jQuery Autocomplete Source Code and everything looks normal.

Has anyone experienced this before?

Upvotes: 3

Views: 1041

Answers (3)

Code Spy
Code Spy

Reputation: 9964

Try Search option in autocomplete as follow:

$(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();  
    }
});

Upvotes: 2

Suvonkar
Suvonkar

Reputation: 2460

I think in the autocomple configuration autoFill: true is defined. Remove this one it will solve the problem.But in that case after writing of the "san f" it will not automaticaly fill the "san Francisco, CA".

Upvotes: 1

Glennular
Glennular

Reputation: 18215

To get around this issue:

To the KEY object add:

    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; 

Upvotes: 1

Related Questions