Skip to content

Instantly share code, notes, and snippets.

@parisnakitakejser
Created June 1, 2015 11:37
Show Gist options
  • Save parisnakitakejser/d958466ea48fddc001a2 to your computer and use it in GitHub Desktop.
Save parisnakitakejser/d958466ea48fddc001a2 to your computer and use it in GitHub Desktop.
Boostrap 3.x - Typeahead - jQuery
Search: <input type="text" value="" class="typeahead" />
<input tyep="hidden" id="inputTmpID" value="" />
$(function() {
var $input = $('.typeahead');
$input.keydown(function(){
$input.typeahead({source:function(query, process){
$.post('{url}',{
'q' : query
},function(data){
return process(data.contentList);
},'json');
}
});
}).change(function() {
var current = $input.typeahead("getActive");
if (current) {
if (current.name.toLowerCase() == $input.val().toLowerCase()) {
$('#inputTmpID').val(current.id);
} else {
// do somthing else
}
} else {
// none active values
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment