I'm using Select2 with ajax. Everything works fine, when the user click on the item they want, I use the on(change) function as specified by the documentation for doing some stuff.
$("#e6").on("change", function(e) {
$('input#Destination').val(e.val);
});
});
The return value (e.val) is the data.id value from the ajax call, but my data object has "name", "id" and "type".
I can add code to dataFormatSelection() but this doesn't sound logic and is confusing.
function dataFormatSelection(data) {
console.log(data.name + "|" data.id + "|" + data.type);
return data.name;
}
How can I access the whole data object (instead of just data.id) at the on("change".. event?
$input.select2('data').find(item => item.element.selected)
. Tested with Select 2 v4.0.12 – Unknot