3

The Jquery autocomplete (LINK) has an option to turn it off, which looks like this:

$(input).autocomplete({ disabled: true });

I would like it to be turned off because its default settings is to respond on keyup. I much rather have it function on keydown. So I turned it off and I wrote a function with an event keydown like this:

timer = 0;
function func (){ 

var val = $(input).val();
$(input).autocomplete('search', val);
}


$(input).live('keydown', function(){

    if (timer) {
        clearTimeout(timer);
    }

    timer = setTimeout(func, 50000); 
     $(input).autocomplete( "enable" );
});

It doesn't work...meaning it does not do search after 50000 ms but instead it does the default setting with keyup. What should I change?

2
  • Why would you rather have it work on keydown? Commented May 7, 2012 at 20:02
  • @Andrew Whitaker because its faster Commented May 7, 2012 at 20:03

2 Answers 2

1

Add a keyup event and stop the event propogation.

Add a keydown event and call it like this: $("input").autocomplete('search', 'demo-value');

$(input).autocomplete().keyup(function(event) {
  event.stopPropagation();
}).keydown(function() {
$(this).autocomplete('search', $(input).val());  //this or $(input)...
});
Sign up to request clarification or add additional context in comments.

1 Comment

Still have to test it, but it looks good (I think this will work) Thanks(:
0
$( "#autocomplete" )
      .keydown( function( event ) {
            var isOpen = $( this ).autocomplete( "widget" ).is( ":visible" );
            var keyCode = $.ui.keyCode;
            if ( !isOpen && ( event.keyCode == keyCode.UP || event.keyCode == keyCode.DOWN ) ) {
                  event.stopImmediatePropagation();
            }

      })
      .autocomplete({
            source: someSource
      });

2 Comments

Thanks, what do you mean with id autocomplete? Do you mean the input?? What is keyCode.UP/DOWN??
This example was posted from the jquery forums with regards to a user trying to get the up and down arrows to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.