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

here demo http://jsfiddle.net/dhirajbodicherla/psjtq/21/


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -