Select2 issue

Select2 issue

ptaylorptaylor Posts: 28Questions: 7Answers: 0

I'm using Select2 to allow me to select two (and only two) items from a dropdown list. I've built the dropdown list, but it allows me to select more than two items.

The select2 website mentions the "maxSelectionLength" parameter, but in their code example, they use "maximumSelectionLength". I've tried it both ways. I've tried the "2" with and without quotes. I've tried putting the max option as an attribute. I've tried various combinations of the above. Nothing has given me the desired result. It just looks like this option is being ignored.

Any idea what I'm doing wrong?

Below is my code:

editor = new $.fn.dataTable.Editor( {
        ajax: "/lte_sim/modems.php",
        table: "#modems",
        fields: [ {
                label: "Store:",
                name: "modems.store_id",
            }, {
                label: "SIMs:",
                name: 'sims[].id',
                type: "select2",
                attr: {
                    multiple: "multiple"
                },              
                opts: {
                    maximumSelectionLength: "2"
                }               
            }, {
                label: "Modem MEID:",
                name: "modems.meid"
            }, {
                label: "Active Vendor:",
                name: "modems.vendor_id",
                type: "select2",
                opts: {
                    minimumResultsForSearch: "Infinity"
                }
            }
        ]
    } );

This question has an accepted answers - jump to answer

Answers

  • ptaylorptaylor Posts: 28Questions: 7Answers: 0

    Found my issue. I was looking at the docs for version 4.0.0, which is what the Select2 website has moved to. In the 3.5.2 docs, this item is "maximumSelectionSize".

    Should I be using 3.5.2, or is it safe to run 4.0.0 with Editor?

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Answer ✓

    Good to hear you found the issue.

    I haven't yet tried using Select2 4.0.0 with Editor yet. It looks like they have changed a number of things, so there might well be incompatibilities. I've added it to my list of plug-ins to look at!

    Regards,
    Allan

  • jtoler5jtoler5 Posts: 88Questions: 32Answers: 3

    Any update on Select2 4.0.0 with Editor?

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    Not yet - sorry. Overwhelmed with the number of things to do at the moment, but this is still on the list. I'll probably get Editor 1.5 out of the door before this.

    Allan

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    I've just tried Select2 4.0.0 (release) with the latest version of the Editor plug-in and it appears to just work out of the box. 4.0.0 will the version that the plug-in will refer to when I deploy Editor 1.5.

    Allan

This discussion has been closed.