switchery icon indicating copy to clipboard operation
switchery copied to clipboard

Duplicating switcherry when the checkbox added dynamically

Open Umeshagouda opened this issue 7 years ago • 4 comments

Hi Guys, Please check the below issue, when i added row dynamically the older checkbox getting duplicated. Here is the code im using when add button clicked -

var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch2')) elems.forEach(function(html) { var switchery = new Switchery(html); });

@abpetkov Please suggest me how can i avoid that duplication issue. Thanks,

switch

Umeshagouda avatar Jul 18 '17 11:07 Umeshagouda

+1

wkjesus avatar Aug 01 '17 23:08 wkjesus

You need to check that it has not already be instantiated. You can check for the presence of the switchery data element. Something like:

elems.forEach(function(html) {

if(!html.getAttribute('data-switchery')){
var switchery = new Switchery(html);
}
}

cweb187 avatar Oct 16 '17 18:10 cweb187

I believe this check should be built-in.

vborovikov avatar Jun 25 '18 12:06 vborovikov

Works fine this solution. Thanks bro..

sedatkumcu avatar Jan 15 '22 09:01 sedatkumcu