select2 - initselection error
Asked Answered
M

1

9

I am getting the following error when using select2 plugin on initSelection.

Error: Uncaught Error: No select2/compat/initSelection is the error I am getting.

Hope somebody helps me in sorting out the inistselection issue.

JS:

  $(".doctor_id_pat").select2({
    placeholder: "Search Users",
    minimumInputLength: 2,
    ajax: {
        url: "/listallergiesajax",
        dataType: 'json',
        data: function(term) {
            return {
                q: term
            };
        },
        results: function(data, page) {
            return {

                results: $.map(data, function(item) {

                    return {
                        text: item.text,
                        id: item.id
                    }
                })

            };
        },
    },
    initSelection: function(element, callback) {

        $.ajax("/listallergiesajax", {
            dataType: "json"
        }).done(function(data) {

            callback(data.results[0]);

        });
    }
});
Miserly answered 28/4, 2015 at 12:10 Comment(3)
$(".doctor_id_pat").select2({}); what is select2?Reprieve
It is a plugin for select options. @ReprieveSmite
Deprecated in Select2 4.0. This has been replaced by another option and is only available in the full builds of Select2.Walz
Y
25

Select2 v3.5.2 uses the initSelection method. Select2 v4 has a different approach.

For information on how to upgrade (initSelection and other stuff) see https://select2.org/upgrading/migrating-from-35#removed-the-requirement-of-initselection.

Yeargain answered 11/5, 2015 at 8:4 Comment(2)
This information has changed to this link.Outlander
@joost, I had exact same problem as cr0ss but this does not help me by just referencing to select2 resource as it is poorly documented. It is better to correct cr0ss code in his question to make it working. So other people like me can see how the working code look like. Hope you see this point. Thanks!Aorangi

© 2022 - 2024 — McMap. All rights reserved.