I'm using Devbridge Autocomplete (https://www.devbridge.com/sourcery/components/jquery-autocomplete) on an input field type text and reading results from an array.
Is there a way to:
1) Only allow to select from the list of results and not type anything else in the field
2) If no results are found, trigger a function
Code:
var people = ['Ross Chapman', 'Curtis Gomez', 'Dolores Gonzales'];
$('.people').autocomplete({
lookup: people
});
You can use onSearchComplete method as mentioned in the docs here.
second parameter suggestions is an array of suggestions as letters are being typed in the input. So by checking
suggestions.length
we can catch the condition when the suggestions array is empty, meaning no results found.Here is a demo http://jsfiddle.net/dhirajbodicherla/PSJTQ/21/