Disable and enable jquery autocomplete

JQuery ( LINK) autocomplete has the ability to disable it, which looks like this:

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

I would like it to be disabled because its default settings are to respond to keystrokes. I use keydown function much better. So I turned it off, and I wrote a function with this way:

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

This does not work ... means that it does not search after 50,000 ms, but instead it does the default setting using keyup. What should i change?

+3
source share
2 answers

Add a keyup event and stop the signal propagation.

Add a keydown event and name 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)...
});
+1
source
$( "#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
      });
0
source

All Articles