I have a problem with the jQuery's Select2.
When the page loads, if O click on the search result it will select and trigger the event onchange, but only the first time.
If I search another time, it won't.
Here's my code (it's an Ajax based search):
jQuery('#search_code').select2({
'width': '600px',
'tokenSeparators': [',', ' '],
'closeOnSelect': false,
'placeholder': 'scan or type a SKU or product or ESN',
'minimumInputLength': 1,
'ajax': {
'url': 'lookProduct',
'dataType': 'json',
'type': 'POST',
'data': function (term, page) {
return {
barcode: term,
page_limit: 3,
page: page
};
},
'results': function (data, page) {
return {
results: data
};
}
}
}).on('change', function (e) {
var str = $("#s2id_search_code .select2-choice span").text();
DOSelectAjaxProd(this.value, str);
//this.value
}).on('select', function (e) {
console.log("select");
});
$(document).on('change', 'span#search_code', function(...
and tell if it works. Replace span by div if #search_code is id to a div or by "element" whatever type of "element" it is. – Spitter