Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

Jstree and select2 conflict


Hi,

Im using jstree and a modal with select2 dropdown, and whenever i load the jstree.bundle.js select2 gets an error "select2 is not a function". I'm using the plugins.bundle.js which contains the select2 function which is above the jstree.bundle.js. What can i do to fix this?


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (6)


Both jstree and select2 depend on jQuery, and if jQuery is reloaded or overwritten, it can break select2. Try checking the console for errors related to jQuery.
sprunki retake



Make sure that the JavaScript file containing Select2 (select2.js or plugins.bundle.js in your case) is loaded smash karts before the jstree.bundle.js file. The order of loading is important, otherwise Select2 will not be defined before you try to use it.



Hi,

In our build, it seems JSTree works fine. You can check it here. Please note that Select2 is globally included in the plugins.bundle.js.

May I know your Metronic version?

Regards.



Hi thanks for the reply, is there an example where jstree and select2 are on the same page? It seems that whenever i load jstree.bundle.js select2 does not work.



Hi,

I just tested Select2 with jStree with the latest Metronic 8.3.2 and it worked well:

<img src="https://i.imgur.com/7KTXGRE.png" alt="">

Please make sure that you include assets/plugins/custom/jstree/jstree.bundle.js after the assets/plugins/global/plugins.bundle.js.

Regards,
Sean



Hi,

I am using metronic version 8.1.8 and facing with same problem, do you have any suggestion?


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(