Introducing CrudHunt:Open-source Full-stack CRUDs for Next.js by KeenThemes
Browse CrudHunt

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
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • 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
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(