Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to trigger the autocomplete #236

Open
nomoregrapes opened this issue Sep 14, 2016 · 6 comments
Open

How to trigger the autocomplete #236

nomoregrapes opened this issue Sep 14, 2016 · 6 comments

Comments

@nomoregrapes
Copy link

Can I manually trigger the autocomplete function?

I want to do something along the lines of...

//usual initialization of easyautocomplete on ".autocomplete_input" 
//when specific/external event happens...
var someNewValueIWantToAddWithJavascript = "United Kingdom";
$(".autocomplete_input" ).val(someNewValueIWantToAddWithJavascript);
$(".autocomplete_input" ).trigger("change"));

But the trigger("change") doesn't trigger the ajax call for autocomplete and so the results list never displays. I figure there must be an easy way to do this, but I've tried several triggers and to no success.

@ronnievisser
Copy link

same problem here, have you solved it?

@midnightcodr
Copy link

Wondering the same thing ...

@princeofnaxos
Copy link

princeofnaxos commented Oct 31, 2016

There is no trigger event, but this workaround works for me:

var e = jQuery.Event("keyup");
e.which = 8; //choose the one you want
e.keyCode = 8;

$(input).val(value).trigger(e);

It's not perfect (the list won't disappear when clicking an item), but it is at least something.

@princeofnaxos
Copy link

I made some changes to the script:
jquery.easy-autocomplete.js.zip

and now I can do this:

$(input).val(value).trigger('change');

@socheatsok78
Copy link

You can just use key 41

var evt = jQuery.Event("keyup");
evt.keyCode = 41; // 41 key is for select
$(e.target).trigger(evt);

It quite annoying that this has to be done this way, but that fine.

@ThiagoDosSantos
Copy link

@socheatsok78 you save my day! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants