Can not make MD Autcomplete working


Topic: Can not make MD Autcomplete working

assoumouad free asked 2 years ago

Expected behavior

Actual behavior No working

Resources (screenshots, code snippets etc.)

==========================================

$("#form-autocomplete").on("keyup", function(e){
    $.ajax({
        url: '{{ route('autocomplete') }}',
        type: "GET",
        cache: false,
        data: { input: e.target.value }//,
        //headers: { Authorization: "Bearer " + token } // your API token if needed
    }).done(function (response) {
        // Map response data if needed
        var data = response.map(function (item) {
            return item.FirstName + item.Number
        });
        $("#form-autocomplete").mdbAutocomplete({ data: data });
    });

});

public function autocomplete(Request $request)
{
    $search = $request->get('query');
    $data = User::select('name')
            ->where('name','LIKE','%'.$search.'%')
            ->get();
    //$data = json_encode($result);
    //return $data;
    return response()->json($data);
}

==================================================

... User name {{ csrf_field() }} Validate previous() }}">Cancel

Grzegorz Bujański staff commented 2 years ago

Hi. Autocomplete is a pro component. Did you have pro license?


assoumouad free commented 2 years ago

Hi, Yes, I have pro licence.


Grzegorz Bujański staff commented 2 years ago

Do You have any errors in console? Data from API is Array or JSON. I suppose it's JSON and that may be the reason. The data should be an array.


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Opened

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.17.0
  • Device: PC
  • Browser: edge
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: No