I'm using Select2JS 4.0.5 with PHP and jQuery 3.2.1. jQuery is included first, then right after that select2js then after that the rest of JS libraries. My code
if ($("#company").length > 0){ // The code below works with typeaheadJS
$('#company').select2()({
source: function (query, syncResults, asyncResults) {
$.ajax({
url: "common/search.php",
data: 'query=' + query,
dataType: "json",
type: "POST",
success: function (data) {
asyncResults($.map(data, function (item) {
return item;
}));
}
});
}
});
}
I keep getting Error: No select2/compat/inputData
Similar questions said that if I include the full version instead this error will be fixed. I if I do that, the error would become
TypeError: $(...).select2(...) is not a function
Changing from an input
tag to a select
tag worked for me.
Instead of:
import 'select2'
I did:
import 'select2/dist/js/select2.full'
You need to include the full version, select2.full.js
This version support input type and not just the select.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With