Używam select2 z AJAX (kod poniżej):Set dane Select2 po wkładce z AJAX
$(".select2-ajax").select2({
placeholder: "Search user",
minimumInputLength: 1,
ajax: {
url: $('#url-search-client').val(),
dataType: 'json',
type: 'post',
data: function (term, page) {
return {
filter: term
};
},
results: function (data, page) {
return {results: data};
}
},
width : '50%',
formatInputTooShort: function() {return 'Informe mais caracteres'; },
formatResult: formatResultSelectAjax, // omitted for brevity, see the source of this page
formatSelection: formatSelectAjaxValue, // omitted for brevity, see the source of this page
dropdownCssClass: "bigdrop" // apply css that makes the dropdown taller
});
Cóż, jeśli nie znaleziono klienta, użytkownik może użyć przycisku, aby otworzyć modalnego i dodać nowego klienta, czy możliwe jest użycie zwrotu (json z identyfikatorem i namae) nowego klienta i umieszczenie danych (np. nazwy) w wybranym2 jako wybrana?
$('.btn-form-client').click(function() {
$.ajax({
url: $('#frm-client').attr('action'),
dataType: 'json',
type: 'post',
data: $('#frm-client').serialize()
}).done(function (data) {
$('#modal-client').modal('hide')
});
return false;
});
Czy możesz to wykonać? – Sebastialonso