0
In the <select>
the records coming from the database are listed, but when clicking on the record, it is not selected.
function searchClasseDisciplina() {
const input = $('#form-classe').find('#disciplina');
const token = sessionStorage.getItem('token');
input.select2({
placeholder: 'Disciplina',
allowClear: true,
minimumInputLength: 1,
language: {
errorLoading: function () {
return 'registros não encontrados';
},
searching: function () {
return null;
},
inputTooShort: function () {
return 'digite 1 ou mais caracteres';
}
},
ajax: {
url: function (params) {
return getApi() + '/dis/'+params.term;
},
dataType: 'json',
headers: { 'x-access-token': token },
processResults: function (data) {
return {
results: data.results.map(x => ({
dis_id: x.dis_id,
text: $( /*html*/ `
<span>${x.dis_nome}</span>
<small class="pull-right">Cód.: <b>${x.dis_codigo}</b></small>
`)
}))
};
},
},
}).on("select2:select", function () {
$.ajax({
type: 'get',
url: getApi() + `/dis/${input.val()}`,
cache: false,
contentType: "application/json;charset=utf-8",
headers: { 'x-access-token': token },
success: function (response) {
addDisciplinaToClasse(response);
},
error: function (error) {
showError(error);
},
});
});
openSelect(input);
}
That’s right, the correct is: id: x.dis_id Thank you very much!
– Desenvolvimento DWM Tecnologia