javascript - Using Devbridge Autocomplete, is there a way to detect no results? -
i'm using devbridge autocomplete (https://www.devbridge.com/sourcery/components/jquery-autocomplete) on input field type text , reading results array.
is there way to:
1) allow select list of results , not type else in field
2) if no results found, trigger function
code:
var people = ['ross chapman', 'curtis gomez', 'dolores gonzales']; $('.people').autocomplete({ lookup: people });
you can use onsearchcomplete method mentioned in docs here.
onsearchcomplete: function (query, suggestions) {}
second parameter suggestions array of suggestions letters being typed in input. checking suggestions.length
can catch condition when suggestions array empty, meaning no results found.
var people = ['ross chapman', 'curtis gomez', 'dolores gonzales']; $('.people').autocomplete({ lookup: people, onsearchcomplete: function (query, suggestions) { if(!suggestions.length){ console.log('no suggestion'); } } });
Comments
Post a Comment