diff --git a/assets/controllers/elements/sidebar_tree_controller.js b/assets/controllers/elements/sidebar_tree_controller.js index 6f43bbe3..ca9ac515 100644 --- a/assets/controllers/elements/sidebar_tree_controller.js +++ b/assets/controllers/elements/sidebar_tree_controller.js @@ -10,6 +10,11 @@ export default class extends TreeController { _storage_key; connect() { + //Check if the tree is already initialized, if so then skip initialization (useful when going back) to in history using Turbo + if(this._isInitialized()) { + return; + } + const default_mode = this.element.dataset.defaultMode; this._storage_key = 'tree_' + this.element.id; diff --git a/assets/controllers/elements/tree_controller.js b/assets/controllers/elements/tree_controller.js index 6631ecac..44a4ee34 100644 --- a/assets/controllers/elements/tree_controller.js +++ b/assets/controllers/elements/tree_controller.js @@ -97,6 +97,21 @@ export default class extends Controller { $(tree).treeview('search', [data]); } + /** + * Check if the tree is already initialized (meaning bootstrap treeview was called on the object) + * @private + */ + _isInitialized() { + const $tree = $(this.treeTarget).treeview(true); + + //If the tree is not initialized yet, we just get an empty jquery object with the treeview functions missing + if(typeof $tree.findNodes === 'undefined' ) { + return false; + } + + return true; + + } _getData() { //Use lambda function to preserve this context diff --git a/templates/base.html.twig b/templates/base.html.twig index 6cbde30f..a7ec1300 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -62,7 +62,7 @@
{% block body %}