devbridge / jQuery-Autocomplete

Ajax Autocomplete for jQuery allows you to easily create autocomplete/autosuggest boxes for text input fields
https://www.devbridge.com/sourcery/components/jquery-autocomplete/
Other
3.56k stars 1.66k forks source link

onSelect fires on clicking input box #644

Open oshihirii opened 7 years ago

oshihirii commented 7 years ago

Hello,

I am just testing jQuery-Autocomplete and have set up a simple example from documentation:

var countries = [
   { value: 'Andorra', data: 'AD' },
   // ...
   { value: 'Zimbabwe', data: 'ZZ' }
];

$('#autocomplete').autocomplete({
    lookup: countries,
    onSelect: function (suggestion) {
        alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
    }
});

The alert fires when selecting the suggestion (which is expected), but then it also fires when clicking on the input box again and gets stuck in a loop of showing the alert.

How can this be avoided?

I am wanting to test more advanced examples to (ajax, templated results, multiple value search etc), but just want to make sure this issue can be resolved before proceeding.

Thank You.

[Am using: https://cdnjs.cloudflare.com/ajax/libs/jquery.devbridge-autocomplete/1.4.2/jquery.autocomplete.min.js]

benoitongit commented 7 years ago

Same issue here :/

oshihirii commented 7 years ago

@benoitongit - fyi i made highly commented demo here, it may help! https://codepen.io/oshihirii/pen/EvMjZm

benoitongit commented 7 years ago

Thanks :) Looks like adding triggerSelectOnValidInput: false as option fix this issue

oshihirii commented 7 years ago

Cool 👍

geekonthepc commented 5 years ago

Thanks, had the same issue.

tgice commented 3 years ago

And a year later, also thanks, this was bugging me and glad to see that option.