XF 2.0 Select2

canina

Active member
I want to use select2 in the forum. how do I do it?
What I did here came out wrong

Code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
 
<script>
 
XF.Runselect = XF.Element.newHandler({
 
 init: function(){
 
    $('.js-example-basic-multiple').select2({
       tags: true,
       tokenSeparators: [',', ' '],
    });
    this.alert();
},

alert: function(){
    alert('The text changed to red and underline...');
  }
});
 
 
 XF.Element.register('Runselect', 'XF.Runselect');

</script>

<xf:select data-xf-init="Runselect " class="js-example-basic-multiple" multiple="multiple">
    
    <xf:option value="1">
        orange
    </xf:option>
    <xf:option value="2">
        apple
    </xf:option>
    <xf:option value="1">
        banana
    </xf:option>
    
</xf:select>
 
I realized that sending personal messages in the forum also has SELECT2. (tour-domain/forum/index.php?conversations/add)
How can I use the code of the forum system itself?
 
@Chris_D,
I hate to bounce threads, but this time it's very urgent for me to develop the plug-in and no one answers.
How to use with select2.
Thanks in advance.
 
You can look at the token_input template to see how we load Select2 (and the CSS).

You can't embed <script> tags in XF if you want them to work with the JS framework. You'd generally use <xf:js /> tags, preferably to load a file. token_input has an example of this, though there are others as well.
 
Back
Top Bottom