Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No select2/compat/inputData

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

like image 439
Lynob Avatar asked Feb 15 '18 11:02

Lynob


3 Answers

Changing from an input tag to a select tag worked for me.

like image 110
Spankied Avatar answered Oct 18 '22 15:10

Spankied


Instead of:

import 'select2'

I did:

import 'select2/dist/js/select2.full'
like image 35
Dorian Avatar answered Oct 18 '22 14:10

Dorian


You need to include the full version, select2.full.js This version support input type and not just the select.

like image 16
Bettinz Avatar answered Oct 18 '22 13:10

Bettinz