I have a JavaScript function that copies a row of components for adding elements dynamically. This works for other types of components, but not with select2.
It is done by cloning the row:
$($(this).data(“target”).find("[data-toggle=fieldset-entry]:last").clone(true, true);
But if there is a select2 component in the row, after I call select2(), component suddenly has two dropdowns, with the other one not working and other one throwing a bunch of errors to console if I click it.
I have a bunch of attributes that need to be copied (for instance Ajax callback function names are defined as attributes) so just creating an empty select2 component won’t work.
Can I somehow use clone or do I need to do the whole function differently?