From 25244f4fc20a48a11d74623ada7bde3f10d2ae13 Mon Sep 17 00:00:00 2001 From: Aleks4k <84202397+Aleks4k@users.noreply.github.com> Date: Mon, 11 Sep 2023 17:29:29 +0200 Subject: [PATCH] Fixed JQuery clone problem. If you've ever used .clone() in jQuery, you have encountered an issue where buttons become unresponsive after cloning. This occurs because the cloned element is already rendered, and that's what we need to address. To resolve this, we've implemented a check to determine if an element has already been rendered. If it has, we remove all elements added in the previous call to the .render() function and then proceed to render it once more. --- js/bootstrap-toggle.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/js/bootstrap-toggle.js b/js/bootstrap-toggle.js index 533914e..803add4 100644 --- a/js/bootstrap-toggle.js +++ b/js/bootstrap-toggle.js @@ -46,6 +46,11 @@ } Toggle.prototype.render = function () { + if(this.$element.nextAll().last().is('div.toggle-group')) { + var parentElement = this.$element.parent(); + this.$element.insertBefore(parentElement); + parentElement.remove(); + } this._onstyle = 'btn-' + this.options.onstyle this._offstyle = 'btn-' + this.options.offstyle var size = this.options.size === 'large' ? 'btn-lg'