Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable and enable Jquery autocomplete

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?

like image 572
Youss Avatar asked Mar 15 '26 05:03

Youss


1 Answers

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)...
});
like image 150
lucuma Avatar answered Mar 16 '26 18:03

lucuma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!