i'm using laravel 5.1 and i try to add some autocomplete into my form, it is not return an error but it's always return unable to find any. i'm very new in javascript. please help me to fix it
here is my template:
{!! Form::label('Name', 'Name:') !!}
{!! Form::text('name',null,['class'=>'form-control', 'id'=>'users']) !!}
here is my route :
Route::get('/', 'SearchController@index');
Route::get('/query','SearchController@query');
here is my controller
class SearchController extends Controller {
public function index() {
return View::make('template');
}
public function query() {
$query = Input::get('name');
$res = User::where('name', 'LIKE', "%$query%")->get();
return Response::json($res);
}
}
here is my main.js
jQuery(document).ready(function($) {
var sugest = new Bloodhound({
remote: '/bookstore/query?name=%QUERY%',
// '...' = displayKey: '...'
datumTokenizer: Bloodhound.tokenizers.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace
});
sugest.initialize();
$("#users").typeahead({
hint: true,
highlight: true,
minLength: 2
}, {
source: sugest.ttAdapter(),
name: 'engine',
displayKey: 'name',
templates: {
empty: [
'<div class="empty-message">unable to find any</div>'
]
}
});
});
Can I suggest another autocomplete javascript library. How about SELECT2. here is the link. https://select2.github.io/examples.html . it's easy to implement. I used typeahead before and it took me a day or two to get it work.