grouma
grouma

Reputation: 626

Select2 options in MeteorJS

I am trying to instantiate a multi-select box with Meteor JS and Select2. My html resides in a template as follows:

<template name="selectbox">
     <select id="testbox">
         <option value="AL">Alabama</option>
         <option value="AL">Washington</option>
     </select>
</template>

Within my client js I have the following code:

Template.selectbox.rendered = function(){
    var options = { allowClear : true, multiple : true }
    $("#testbox").select2(options);
};

Unfortunately my browser's console produces the following error:

Exception from Deps afterFlush function: Error: Option 'multiple' is not allowed for Select2 when attached to a <select> element.

I have also tried placing the following code directly in my client js file (as well as within Template.selectbox.create):

$(document).ready(function(){
    var options = { allowClear : true, multiple : true }
    $("#testbox").select2(options);
});

Unfortunately I receive the same error. The peculiar thing is I receive no error if my options are simply:

var options = { allowClear : true, placeholder : 'test' }

Neither option appears to take affect. However, The rendering of the select box is that of selct2.

Any idea what could be the issue? Thanks in advanced.

Upvotes: 0

Views: 1706

Answers (1)

Hubert OG
Hubert OG

Reputation: 19544

See how the example on select2 website is made. According to that code, you should add multiple attribute to the select tag, not to js method parameters.

So in your template replace <select id="testbox"> with <select multiple id="testbox">.

Upvotes: 1

Related Questions