How to make an auto complete in the Standard

Asked

Viewed 115 times

0

 <input class="typeahead form-control" style="margin:0px auto;width:200px;" type="text">
              </div>
              <script type="text/javascript">
                var path = "v1/versoes/autocompletesistema";
                $('input.typeahead').typeahead({
                    source:  function (query, process) {
                    return $.get(path, { query: query }, function (data) {
                          return process(data);
                    });
                  }
                });
              </script> 






public function autocompletesistema( Request $request ){
        $sistemas = Sistema::select("sistema as descricao", "id")
                        ->where("sistema","LIKE","%{$request->input('query')}%")->get();
    return response()->json($sistemas);
  • Boy, if you don’t detail what you’re up to and what you need, it’s hard for anyone to cooperate

  • The code is that there returns nothing

  • Guilherme, what version of the typeahead library are you using?

  • @Guilherme.ramos understood this but when asking question in forum it is recommended to summarize as for example: - What you have done, what mistakes there were, if there were, which part is difficult etc

1 answer

0

I changed some things in your code and typeahead here made the requests, basically I reversed the parameters query and proccess, and added the call process.process(data) on the return. I am using version 0.11.1 of typeahead.js which is the latest.

$(document).ready(function(){
  var path = "v1/versoes/autocompletesistema";
  $('input.typeahead').typeahead(null ,
  {
    source: function (process, query) {
      return $.get(path, { query: query }, function (data) {
          return process.process(data);
      });
    }
  });
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.