Created
June 1, 2015 11:37
-
-
Save parisnakitakejser/d958466ea48fddc001a2 to your computer and use it in GitHub Desktop.
Boostrap 3.x - Typeahead - jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Search: <input type="text" value="" class="typeahead" /> | |
<input tyep="hidden" id="inputTmpID" value="" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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