Mathew Mathew - 2 years ago 149
Javascript Question

jQuery autocomplete value

I'm writing app in rails and I am using twitter-typeahead-rails for typeahead and searchkick for search. I wrote code in js to automatically search after change in input. When I'm taking value of input after change it takes value with hint of typeahead however I want to take value without that hint.

var numbers;
numbers = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: "/local/autocomplete"


$(document).ready(function() {
// instantiate the typeahead UI
$('.typeahead').typeahead(null, {
displayKey: 'name',
source: numbers.ttAdapter()
$('.typeahead').on('input', function(e){
type: "GET",
url: '/local/search',
data: {local: $('.typeahead').val()}

Answer Source

I do not know about typeahead rails. If it works the same as the original typeahead plugin then you can disable the hint via option hint: false

If you don't want to disable the hint: typeahead creates a seperate input for the hint, by default:

.tt-hint contains the hint

.tt-input contains the user input

So, in your script get the value from .tt-input

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download