I'm using twitter typeahead with bloodhound suggestion engine, everything is working fine. Below is my code snippet
// instantiate the bloodhound suggestion engine
var searchData = new Bloodhound({
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.value);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '<?php echo 'http://localhost/project1/perform/find?q=%QUERY'; ?>',
filter: function (data) {
return $.map(data.results, function (record) {
return {
title: record.title,
pageURL: record.pageURL
};
});
}
}
});
// initialize the bloodhound suggestion engine
searchData.initialize();
searchData.clearRemoteCache();
// instantiate the typeahead UI
$('#find').typeahead({
hint:false,
highlight: true,
minLength: 3
}, {
name:'search-data',
displayKey: 'title',
source: searchData.ttAdapter(),
templates: {
empty:[
'<strong>No Results Found.</strong>'
],
suggestion: Handlebars.compile('<p>{{title}}</p>')
}
}).on('typeahead:selected', function (e, suggestion) {
setTimeout(function(){document.location = suggestion.pageURL;}, 500);
}).on('typeahead:closed', function (e){
$loadingImg.hide();
});
I want to do some operations like displaying posting button, etc., when remote server returns zero results, how can I catch this event ?