I worked with typeahead.js
and downloaded data using the BloodHound remote
option.
Everthing works as expected, except that when I enter only spaces
in the textbox
typeahead still sends ajax call
.
I want to know if there is a way to prevent ajax call
if there are only spaces
in the text box. I am looking for similar behavior like trim
.
Here is my code. I tried using the prepare
function, but no luck.
var dataSource = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('ProductID', 'ProductName'), queryTokenizer: Bloodhound.tokenizers.whitespace, remote: { url: urlVar + "LoadAllProductByProductName/%QUERY", wildcard: '%QUERY', }, sufficient: 3, }); const $tagsInput = $('.txtProductName') $tagsInput.typeahead({ minLength: 3, source: dataSource, hint: false, highlight: true, isBlankString: false }, { limit: 10, source: dataSource, name: 'dataSource', display: function (item) { return item.ProductName }, suggestion: function (data) { return '<div>' + data.ProductName + '–' + data.ProductID + '</div>' }, });
source share