2
The Select2 plugin works normally, the only problem is when I select the item the value put in hidden
(mandatory to bring data via AJAX) is as [Object Value]
and not the value specified by the formatting.
Following form:
<form id="Teste" method="get" action="">
<input type="hidden" id="e6" name="e6" class="select2" style="width: 600px;" />
<input type="submit" value="Enviar" />
</form>
Value in the input hidden
after the selection:
<input type="hidden" id="e6" name="e6" class="select2 select2-offscreen" style="width: 600px;" tabindex="-1" title="" value="[object Object]">
Javascript for Select2 creation:
function formataResultado(item) {
return item.Text;
}
function formataSelecao(item) {
return item.Value;
}
$("#e6").select2({
placeholder: "Selecionar fornecedor",
minimumInputLength: 0,
id: function(data){return {id: data.id};},
allowClear: true,
ajax: {
url: "http://localhost:1396/Lista/_GetDropDownListFornecedor",
dataType: 'jsonp',
quietMillis: 300,
data: function (term, page) {
return {
searchString: term,
pageSize: 60,
pageIndex: page,
};
},
results: function (data, page) {
return {results: data.results, more: (page * 60) < data.total };
}
},
formatResult: formataResultado,
formatSelection: formataSelecao,
dropdownCssClass: "bigdrop",
escapeMarkup: function (m) { return m; }
});
JSON returned by AJAX query made by Select2:
{"results":[{"Selected":false,"Text":"Cezar Barbara","Value":"724"},
{"Selected":false,"Text":"Cezar Barbara","Value":"765"}],
"total":82}
Thanks for the answer, I’ll take a look. When the pagination is correct, the control is in the server.
– Trxplz0
Solved, I had already returned the value with the same idea that you proposed, but it was in the old version and gave problem. After upgrading it worked as expected (3.5.++). Thanks for the help. Remove the part about paging for a next user with doubts don’t make the wrong paging error. The data: data.total is a custom field of my json. Off: I joined your blog and didn’t find any topics, you disabled them or started?
– Trxplz0
@Trxplz0 I haven’t even started... : P
– mgibsonbr
And will? haeuaheuaheuaheu
– Trxplz0
@Trxplz0 hahaha let’s see... (you may notice that I haven’t touched it for so long that the safety certificate EXPIRED!) I have a few drafts started but not finished, any time I publish them. : D
– mgibsonbr