0
I was studying the typeahead.js
with bootstrap 3
, and I’m trying to make an auto-complete request to the server to bring the list options.
This is the plugin I’m using: Github Bootstrap 3 Typeahead
This is the function I use to create auto complete :
$(function(){
var options = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: 'loadNameChoices',
replace: function(url, uriEncodedQuery) {
return url + '?input=' + uriEncodedQuery
},
}
});
options.initialize();
$('#nome').typeahead({source:options.ttAdapter()});
})
When typing a letter in the field, the request is made on the server, which returns a json with names. But autocomplete does not work.
What is the right way to implement this remote autocomplete?
My back-end is done with grails. And in front-end use bootstrap3
+ jquery.
This is the service that returns the json with the names. This service works correctly.
def loadNameChoices(){
render(contentType: "application/json") {
service.loadNames(params['input'])
}
}
If I just do:
$('#nome').typeahead({
source: ['TESTE','TESTE']
});
Autocomplete works. I think there’s a problem with Bloodhound
Which programming language you use?
– Marconi
My backend is grails. Front bootstrap3 + jquery. I added the controller code that receives the request.
– user8078