Create autocomplete for Select Option with Jquery?

Asked

Viewed 352 times

0

I’m trying to make an autocomplete using select with jquery but I’m not getting it. How to do this ?

I’m trying like this

function fillSelect(data) {
    //$('#usuarioSelected').empty();
    if (data['InvestidorMaster'].length > 0) {
        //$.each(data["InvestidorMaster"], function (i, cp) {
        //    $('#usuarioSelected').append('<option value="' + cp.id + '">' + cp.nome + '</option>');
        //});
       //fill select without autocomplete it works 

        //autocomplete
        var suggestions = [];
        $.each(data["InvestidorMaster"], function (i, cp) {
            suggestions.push({ 'value' : cp.id, 'label' : cp.nome});
        });
        $("#usuarioSelected").autocomplete({
            source: suggestions           
        });
    }
} 
  • Have you ever thought about using a plugin that already does this for you? Follow the documentation link of a: https://select2.org/getting-started/basic-usage

  • You want to create the json array?

No answers

Browser other questions tagged

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