Select2 + Jquery - Problem with Autocomplete

0

I was able to make Plugin Select2 work, but autocomplete does not work.

$(function () {

    $("#disciplina").select2({
        placeholder: "Disciplina",
        minimumInputLength: 0,
        ajax:{
            url: "busca.asp",
            type: "post",
            dataType: "json",
            delay: 150,
            data: function(params){
                return{
                    text: params.term
                };
            },
            processResults: function(data, params){
                params.page = params.page || 1;     
                return{ 

                    results: data,
                    pagination:{
                        more: (params.page * 30) < data.total_count
                    }
                };
            },
            cache: true
        }
    });

});

Hasanyoneeverbeenthroughthis?

Returnwithconsole.log(data);

console.log(params);

    
asked by anonymous 23.07.2018 / 22:18

1 answer

1

Problem

Data is not being filtered when a search key is typed.

According to the documentation on the plugin site: link

  

Select2 expects results from the remote endpoint to be filtered on the   server side.

Translation

Select2 expects results returned by the remote endpoint to be filtered from the server side.

Example

In this example date is a function allows you to customize the search url, server-side parameters should be used to filter the list returned.

  

Query parameters will be? search = [term] & type = public

$('#mySelect2').select2({
  ajax: {
    url: 'https://api.github.com/orgs/select2/repos',
    data: function (params) {
      var query = {
        search: params.term,
        type: 'public'
      }

      // Query parameters will be ?search=[term]&type=public
      return query;
    }
  }
});
    
23.07.2018 / 23:12