Using typeahead.bundle.js 0.10.2 I am having trouble getting the latest input a user has typed, into the bloodhound ajax query. I'm POSTing json, and receiving as json successfully, but not able to "get" the latest user query to post it.
I have a dropdown menu of product categories and an input field for the product search. Combined, a user can search for a product in all categories, or search for the product within a single category.
Here's my current code: http://jsfiddle.net/jamcow/b43T9/
As the initial value of #productSearch.val() is empty, that's what goes into the ajax query. https://github.com/twitter/typeahead.js/issues/542 comes close, but I don't see a way to give it the latest queryInput.val()
ajax: {
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({
partialSearchString: searchInput,
category: searchCategoryInput
}),
success: function (data) {
console.log("we got data:");
console.log(data);
}
}
$('#searchproducts').typeahead(null, {
name: 'products',
displayKey: 'Value',
source: products.ttAdapter()
})
Have tried using products.clear();
and products.initialize(true);
as well
What's the best way to get the current query into the ajax request?